首先,需要在父组件的json文件中,引入子组件
{
"usingComponents": {
"day-page": "/pages/First/first/index"
}
}
第二步,在子组件的json文件中,将其设置为组件,即 “component”: true,
{
"component": true,
"usingComponents": {}
}
第三步,在子组件的js文件中,分别设置properties和lifetimes
小程序文档-组件生命周期
// pages/First/first/index.js
Component({
/**
* 组件的属性列表
*/
properties: {
flag: {
type: Number,
value: ''
}
},
// 组件生命周期
lifetimes: {
attached: function() {
console.log(this.data.flag)
}
},
/**
* 组件的初始数据
*/
data: {
},
/**
* 组件的方法列表
*/
methods: {
}
})
最后,在组件的js文件中,使用 this.data.传入的值 即可使用