詳解微信小程序 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.clickViewPage(indexObj)
index.wxss
/**index.wxss**/@import "../temp/temp.wxss";
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
新聞熱點
疑難解答