找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索本站精品资源

首页 教程频道 小程序开发 查看内容

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

作者:模板之家 2017-12-15 08:54 2007人关注

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

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

 
 
 

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

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";


路过

雷人

握手

鲜花

鸡蛋
原作者: 模板之家 来自: 网络收集

全部回复(0)