微信小程序如何使用template添加绑定事件
小编给大家分享一下微信小程序如何使用template添加绑定事件,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!
对于模板的使用,我是想将模板的事件单独出来,其他引用模板的页面中不再掺杂模板事件,比较方便管理,如果还有其他好的解决办法, 请赐教。
template.wxml
<view bindtap="clickView" class="tempClass">temp模板</view>
template.js
var temp = { clickView: function () { console.log("刚刚您点击了temp") } } export default temp
template.wxss
.tempClass { background-color: red; }
index.wxml 引用template模板
<!--index.wxml--> <view>body</view> <include src="../temp/temp.wxml" />
index.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
/**index.wxss**/ @import "../temp/temp.wxss";
看完了这篇文章,相信你对“微信小程序如何使用template添加绑定事件”有了一定的了解,如果想了解更多相关知识,欢迎关注行业资讯频道,感谢各位的阅读!