微信小程序中的事件绑定
前言:
微信小程序中的事件绑定和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中的指令的话,入手会很快
微信小程序中的事件绑定的更多相关文章
- 微信小程序之bindtap事件绑定传参
wxml代码: <view class='fen'> <text bindtap='prev' data-page="{{pageDang}}">上一页&l ...
- 微信小程序中的事件
事件 说明 bindtap bindload 当图片载入完毕时触发,event.detail = {height, width} bind事件绑定不会阻止冒泡事件向上冒泡,catch事件绑定可以阻止冒 ...
- 微信小程序开发 [03] 事件、数据绑定和传递
1.事件绑定 在微信小程序中,事件的绑定依附于组件,当事件触发时,就会执行事件对应的处理函数. 我们回到前几章中的例子,将index页面调整为首页(app.json中调整pages数组元素的顺序),此 ...
- 微信小程序中事件
微信小程序中事件 一.常见的事件有 类型 触发条件 最低版本 touchstart 手指触摸动作开始 touchmove 手指触摸后移动 touchcancel 手指触摸动作被打断,如来电提醒,弹窗 ...
- 微信小程序中,如何阻止多次点击单击事件
在微信小程序中,有自制对话框用于提交数据,但是会出现用户连续点击,多次提交数据的情况. //.wxml <view class="acertain" bindtap=&quo ...
- 全栈开发工程师微信小程序-中(中)
全栈开发工程师微信小程序-中(中) 开放能力 open-data 用于展示微信开放的数据 type 开放数据类型 open-gid 当 type="groupName" 时生效, ...
- 全栈开发工程师微信小程序-中
全栈开发工程师微信小程序-中 多媒体及其他的组件 navigator 页面链接 target 在哪个目标上发生跳转,默认当前小程序,可选值self/miniProgram url 当前小程序内的跳转链 ...
- 微信小程序中target与currentTarget
target在事件流的目标阶段:currentTarget在事件流的捕获,目标及冒泡阶段.但事件流处于目标阶段,target与currentTarget指向一样, 而当处于捕获和冒泡阶段的时候,tar ...
- 微信小程序中登录操作-----与-----引用
login.wxml <view> <!-- <image src="./88.png"></image> --> # 在当前目录下 ...
随机推荐
- 9.11 myl模拟赛
9.11 myl 模拟赛 100 + 100 + 0 第一题耗费了太多的时间,导致最后一题没有时间想,直接去写了暴力,而且出题人没有给暴力分.... Problem 1. superman [题目描述 ...
- svg坐标转换
本文内容转自 how-to-translate-from-dom-to-svg-coordinates-and-back-again svg coordinate system Why we need ...
- flutter 监听返回
在项目中遇到了一个场景,A页面必须返回某个tab页,但是A页面可能会调到B,再跳到C,最后回到A.这个时候A的返回肯定是C. 想了一些解决方案,都不如监听A页面的实体键返回或者虚拟键返回来的快速便捷. ...
- git添加公钥后报错sign_and_send_pubkey: signing failed: agent refused operation的解决办法
在服务器添加完公钥后报错 sign_and_send_pubkey: signing failed: agent refused operation 这个时候我们只要执行下 eval "$( ...
- 解决Spring Boot 拦截器注入service为空的问题
问题:在自定义拦截器中,使用了@Autowaire注解注入了封装JPA方法的Service,结果发现无法注入,注入的service为空 0.原因分析 拦截器加载的时间点在springcontext之前 ...
- 【洛谷】P4167 [Violet]樱花
题面 又懒得弄题面,开个传送门吧 分析 人生第一次切数学题,我们先把方程写出来 $$\frac {1}{x}+\frac {1}{y}=\frac {1}{n!}$$ 现在我们知道的条件是x,y都是正 ...
- React.createElement 与 JSX
DOM 向JSX的演进 网页由 DOM 元素构成.React DOM 并不是浏览器的 DOM,而React DOM 只是用来告诉浏览器如何创建 DOM 的方法.通常情况下,我们并不需要 React 就 ...
- 范仁义html+css课程---1、html基本结构
范仁义html+css课程---1.html基本结构 一.总结 一句话总结: html标签中包含head标签和body标签,head标签里面主要写用户不可见的内容,比如字符集编码,body标签里面主要 ...
- SelectKBest
https://www.e-learn.cn/content/python/2198918from sklearn.feature_selection import SelectKBest,f_cla ...
- HearthBuddy的class276以及class247
使用de4dot-cex反编译原版的hearthbuddy得到的 链接: https://pan.baidu.com/s/1hT79LpIjbyvODsjnkSe_5A 提取码: iemx class ...