详解微信小程序 template添加绑定事件
更新时间:2017年06月23日 09:05:05 作者:xiaochun365
这篇文章主要介绍了详解微信小程序 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";
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
相关文章
Javascript中弹窗confirm与prompt的区别
今天小编就为大家分享一篇关于Javascript中弹窗confirm与prompt的区别,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧2018-10-10利用前端HTML+CSS+JS开发简单的TODOLIST功能(记事本)
这篇文章主要介绍了用HTML+CSS+JS做出简单的TODOLIST(记事本)项目,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下2021-04-04
最新评论