小程序自定义组件

component.wxml

<view class='inner'>
    {{ innerText }}
</view>
<slot></slot>

component.wxss

.inner {
    color: red;
}

component.json

{
    component: true
}

component.js

Component({
    properties: {
        innerText: {
            type: String,
            value: 'default value',
        }
    },
    data: {
        someData: {}
    },
    methods: {
        customMethod: function() {}
    }
})

index.wxml

<view>
    <component-tag-name inner-text='Some text'></component-tag-name>
</view>

index.json

{
    usingComponents: {
        component-tag-name: 'path/to/the/custom/component'
        // 组件文件路径
    }
}

  

posted @ 2018-03-25 15:26  东少回忆  阅读(109)  评论(0编辑  收藏  举报