小程序自定义组件
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' // 组件文件路径 } }