前言:

微信小程序中的事件绑定和Vue中的事件绑定其实有很多的相似之处,所以如果有过Vue相关的经验,学起来的话还是比较容易的。

js代码:

// 页面级的js文件必须调用Page函数来注册页面,
// 否则你的页面将无法正常渲染 Page({
parent() {
console.log('parent')
},
father() {
console.log('father')
},
son() {
console.log('son')
}
})

wxss代码: (也就是对应的样式)

.parent{
width: 500rpx;
height: 500rpx;
background-color: red;
margin-bottom: 20rpx;
} .father{
width: 300rpx;
height: 300rpx;
background-color: pink;
} .son{
width: 100rpx;
height: 100rpx;
background-color: yellow;
}

wxml代码:

<!-- bind绑定的事件具有 事件冒泡 -->
<view class="parent" bind:tap="parent">
<view class="father" bind:tap="father">
<view class="son" bind:tap="son"></view>
</view>
</view> <!-- catch绑定的事件会阻止事件的冒泡 -->
<view class="parent" catch:tap="parent">
<view class="father" catch:tap="father">
<view class="son" catch:tap="son"></view>
</view>
</view> <!-- capture-bind 绑定的事件具有 事件捕获 -->
<view class="parent" capture-bind:tap="parent">
<view class="father" capture-bind:tap="father">
<view class="son" capture-bind:tap="son"></view>
</view>
</view> <!-- capture-catch 绑定的事件会阻止事件捕获 -->
<!-- 但是这样的话,在内部嵌套的元素永远无法触发对应的事件处理函数 -->
<view class="parent" capture-catch:tap="parent">
<view class="father" capture-catch:tap="father">
<view class="son" capture-catch:tap="son"></view>
</view>
</view> <!-- mut-bind绑定的事件具有 互斥效果,即"有我没你"的感觉 -->
<view class="parent" mut-bind:tap="parent">
<view class="father" mut-bind:tap="father">
<view class="son" mut-bind:tap="son"></view>
</view>
</view>

总结:

  • 一般开发中的话用的比较多的是前两种
  • 如果会Vue中的指令的话,入手会很快

微信小程序中的事件绑定的更多相关文章

  1. 微信小程序之bindtap事件绑定传参

    wxml代码: <view class='fen'> <text bindtap='prev' data-page="{{pageDang}}">上一页&l ...

  2. 微信小程序中的事件

    事件 说明 bindtap bindload 当图片载入完毕时触发,event.detail = {height, width} bind事件绑定不会阻止冒泡事件向上冒泡,catch事件绑定可以阻止冒 ...

  3. 微信小程序开发 [03] 事件、数据绑定和传递

    1.事件绑定 在微信小程序中,事件的绑定依附于组件,当事件触发时,就会执行事件对应的处理函数. 我们回到前几章中的例子,将index页面调整为首页(app.json中调整pages数组元素的顺序),此 ...

  4. 微信小程序中事件

    微信小程序中事件 一.常见的事件有 类型 触发条件 最低版本 touchstart 手指触摸动作开始 touchmove 手指触摸后移动 touchcancel 手指触摸动作被打断,如来电提醒,弹窗 ...

  5. 微信小程序中,如何阻止多次点击单击事件

    在微信小程序中,有自制对话框用于提交数据,但是会出现用户连续点击,多次提交数据的情况. //.wxml <view class="acertain" bindtap=&quo ...

  6. 全栈开发工程师微信小程序-中(中)

    全栈开发工程师微信小程序-中(中) 开放能力 open-data 用于展示微信开放的数据 type 开放数据类型 open-gid 当 type="groupName" 时生效, ...

  7. 全栈开发工程师微信小程序-中

    全栈开发工程师微信小程序-中 多媒体及其他的组件 navigator 页面链接 target 在哪个目标上发生跳转,默认当前小程序,可选值self/miniProgram url 当前小程序内的跳转链 ...

  8. 微信小程序中target与currentTarget

    target在事件流的目标阶段:currentTarget在事件流的捕获,目标及冒泡阶段.但事件流处于目标阶段,target与currentTarget指向一样, 而当处于捕获和冒泡阶段的时候,tar ...

  9. 微信小程序中登录操作-----与-----引用

    login.wxml <view> <!-- <image src="./88.png"></image> --> # 在当前目录下 ...

随机推荐

  1. input重复上传图片失效的问题

    使用input的file来上传图片 如果是重复选择相同的图片就会失效 解决的办法就是当每次上传完图片后让input的值为空就可以解决了 附上代码 只需在末尾添加这句就行$(this).val(&quo ...

  2. 阿里开源线上应用调试利器 Arthas的背后

    Arthas是一个功能非常强大的诊断工具,功能点很多,例如:jvm信息.线程信息.搜索类中的方法.跟踪代码执行.观测方法的入参和返回参数等等. 作为有追求的程序员,你不仅要知道它能做什么,更要思考它是 ...

  3. Python3OS文件/方法

    Python3OS文件/方法 os模块提供了非常丰富的方法用来处理文件和目录. 方法 描述 os.access(path,mode) 检验权限模式 os.chdir(path) 改变当前工作目录 os ...

  4. Codeforces Round #604 (Div. 1) - 1C - Beautiful Mirrors with queries

    题意 给出排成一列的 \(n\) 个格子,你要从 \(1\) 号格子走到 \(n\) 号格子之后(相当于 \(n+1\) 号格子),一旦你走到 \(i+1\) 号格子,游戏结束. 当你在 \(i\) ...

  5. java使用freemark生成word/pdf

    目录 一. 背景 二.实现的技术选型以及遇到的坑 三.最终的效果 2.1 .doc word效果展示 2.1 .docx word效果展示 2.2 docx word转pdf效果展示 三.准备工作及代 ...

  6. [提权]mysql中的UDF提权

    由于udf提权是需要构造UDF函数文件的,涉及到了写文件.所以本次实验已经将mysql的配置做了改动:–secure-file-priv=''. 剧情须知: secure_file_priv 为 NU ...

  7. SpringBoot集成mybatis,同时读取一个数据库中多个数据表

    SpringBoot集成mybatis,同时读取一个数据库中多个数据表: application.properties: mybatis.config-location=classpath:mybat ...

  8. 深入理解JVM虚拟机10:JVM常用参数以及调优实践

    转自http://www.rowkey.me/blog/2016/11/02/java-profile/?hmsr=toutiao.io&utm_medium=toutiao.io&u ...

  9. java输出程序运行时间

    做了一个MapReduce的小练习,想测试一下程序运行时间: 代码: long start = System.currentTimeMillis(); /*运行的程序主体*/ long end = S ...

  10. Linux下通过nmap扫描局域网内设备,获取ip地址和mac地址

    安装nmap sudo apt-get install nmap 扫描  sudo nmap -sP -PI -PT