欢迎光临,了解微信小程序开发,就上易用通!

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

发布:2017-12-15 08:55浏览: 来源:网络 作者:tianshu

对于模板的使用,我是想将模板的事件单独出来,其他引用模板的页面中不再掺杂模板事件,比较方便管理,如果还有其他好的解 ...

 
 
 

对于模板的使用,我是想将模板的事件单独出来,其他引用模板的页面中不再掺杂模板事件,比较方便管理,如果还有其他好的解决办法, 请赐教。

template.wxml

<view bindtap="clickView" class="tempClass">temp模板view>
  • 1
  • 1

template.js

var temp = {
  clickView: function () {
    console.log("刚刚您点击了temp")
  }
}
export default temp
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

template.wxss

.tempClass {
  background-color: red;
}
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

————————————————————————  index.wxml 引用template模板


<view>bodyview>
<include src="../temp/temp.wxml" />
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

index.js

const App = getApp()
import tempObj from '../temp/temp'

//index.js
//获取应用实例
var indexObj = {
  onShow() {
    console.log("onShow")
  }
}
indexObj["clickView"] = tempObj.clickView
Page(indexObj)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

index.wxss

/**index.wxss**/
@import "../temp/temp.wxss";





免责声明:本站所有文章和图片均来自用户分享和网络收集,文章和图片版权归原作者及原出处所有,仅供学习与参考,请勿用于商业用途,如果损害了您的权利,请联系网站客服处理。