1.组件目录
2.my-component.wxml
<view class="inner">
<text>I am learning wechat app</text>
</view>
<slot></slot>
3.my-component.js
Component({
properties: {
// 这里定义了innerText属性,属性值可以在组件使用时指定
innerText: {
type: String,
value: 'default value',
}
},
data: {
// 这里是一些组件内部数据
someData: {},
},
methods: {
customMethod(){
console.log("I am learning applet of wechat")
}
}
})
4.index.js
const app = getApp()
Page({
data: {
},
onReady: function () {
},
onLoad: function () {
},
showComponent: function () {
this.selectComponent('#myComponent').customMethod() // 调用自定义组件中的方法
}
})
5.index.json
{