首页 > 热点 > 微信 > 正文

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

2024-07-22 01:17:01
字体:
来源:转载
供稿:网友

详解微信小程序 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";

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

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表