微信小程序之自定义组件的使用

components

css样式及html 按照正常书写就可以了

js

// components/TabWacth.js
Component ({
/**
* 组件的属性列表
*/
properties : {
// 用户头像
MySrc : { // 属性名
type : String , // 类型(必填),目前接受的类型包括:String, Number, Boolean, Object, Array, null(表示任意类型)
value : '' // 属性初始值(可选),如果未指定则会根据类型选择一个
},
//判断是否加class
type :{
type : String ,
value : ''
}
},

/**
* 组件的初始数据
*/
data : {

},

/**
* 组件的方法列表
*/
methods : {

}
})

json

{
"component" : true ,
"usingComponents" : {}
}



定义完成我们的组件之后

引用时

在html里引入 和需要传入的值

< TabWacth MySrc= '{{MySrc}}' type= "month" >

在引用的JSON中加入我们的组件名字就可以了

{
"usingComponents" : {
"TabWacth" : "/components/TabWacth/index"
}
}

猜你喜欢

转载自blog.csdn.net/qinlulucsdn/article/details/80846514