在组件中使用
组件js文件
var myBehavior = require('my-behavior')
Component({
behaviors: [myBehavior],
properties: {
myProperty: {
type: String,
msg:'asdad'
}
},
data: {
myData: 'my-component-data'
},
created: function () {
console.log('[my-component] created')
},
attached: function () {
console.log('[my-component] attached')
},
ready: function () {
console.log('[my-component] ready')
},
methods: {
myMethod: function () {
console.log('[my-component] log by myMethod')
},
}
})
组件wxml文件
在引入页面组件之后
可以直接拿到组件js文件中data的msg
my-behavior.js
module.exports = Behavior({
behaviors: [],
properties: {
myBehaviorProperty: {
type: String
}
},
data: {
myBehaviorData: {},
msg:'dadadad'
},
attached: function(){},
methods: {
myBehaviorMethod: function(){}
}})