微信小程序 制作小组件
对于我们日常中一些公共的东西可以封装成组件,然后在各个页面使用。对于小程序,我们也可以封装我们需要的一些公共的东西。
如上图所示,一个小插件,单击是展开,在单击关闭的时候,按钮关闭。
页面的WXML (APP.wxml)
rush:js;">
display:flex;flex-direction:row;">
display:flex;flex-direction:row;">
display:flex;flex-direction:row;">
logo.png">
display:flex;flex-direction:row;">
irsticon.png">
首页
display:flex;flex-direction:row;">
logo.png" bindtap="showAllIcon">
</view>
页面的JS (APP.js)
rush:js;">
var iconList = {}; //设置一个对象名字存放数据
iconList.Wdg= {
//存放要给VIEW层的页面数据,closeAllIcon ,showAllIcon 是对应的方法
data: {
index: 0,close:0
},closeAllIcon: function(e){
this.setData({
close:1
})
},showAllIcon :function(e){
this.setData({
close:0
})
}
};
module.exports=iconList //将接口的进行暴露,方便在外面调用
接下来封装好了,就是该怎么使用了。
在需要的WXML页面:
通过 引入斤页面,再通过
rush:js;">
页面的数据}}">
进行使用。
在需要的WXML页面:
通过var iconList = require('../wdg/iconList');引入对应的JS
rush:js;">
var util= require('../../util/util');
var Page = new util.Page({
Wdgs: [iconList.Wdg]
});
引入对应文件。
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!