当前位置: 移动技术网 > IT编程>开发语言>JavaScript > 详解微信小程序 template添加绑定事件

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

2017年12月12日  | 移动技术网IT编程  | 我要评论

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

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

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网