详解微信小程序 template添加绑定事件

详解微信小程序 template添加绑定事件

对于模板的使用,我是想将模板的事件单独出来,其他引用模板的页面中不再掺杂模板事件,比较方便管理,如果还有其他好的解决办法, 请赐教。

template.wxml

rush:xml;">

template.js

rush:js;"> var temp = { clickView: function () { console.log("刚刚您点击了temp") } } export default temp

template.wxss

rush:js;"> .tempClass { background-color: red; }

index.wxml 引用template模板

rush:js;"> body

index.js

rush:js;"> const App = getApp() import tempObj from '../temp/temp'

//index.js
//获取应用实例
var indexObj = {
onShow() {
console.log("onShow")
}
}
indexObj["clickView"] = tempObj.clickView
Page(indexObj)

index.wxss

rush:js;"> /**index.wxss**/ @import "../temp/temp.wxss";

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持

相关文章

开发微信小程序的用户授权登录功能
小程序开发页面如何实现跳转?
浅谈小程序开发中蓝牙连接错误分析及解决方法
什么是小程序?它有哪些功能?
如何配置小程序开发项目结构?(教程)
怎么把自己的店加入小程序