微信小程序中的事件绑定
前言:
微信小程序中的事件绑定和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> --> # 在当前目录下 ...
随机推荐
- codevs 5972 格子游戏
5972 格子游戏 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description Alice和Bob玩了一个古老的游戏:首先画一个n * ...
- 【概率论】6-4:分布连续性修正(The Correction for Continuity)
title: [概率论]6-4:分布连续性修正(The Correction for Continuity) categories: - Mathematic - Probability keywor ...
- AtCoder Grand Contest 011题解
传送门 \(A\) 直接按时间排序之后贪心就可以了 const int N=1e5+5; int a[N],q[N],c,k,h,t,n,res; inline int min(R int x,R i ...
- 在Mac如何启动MySQL
安装好MySQL服务后(安装步骤可以参考系列经验1).打开“系统偏好设置”,单击下端的“MySQL”图标. 2 在“MySQL”对话框中,单击“启动MySQL服务”按钮. 3 在弹出的窗口中,输入管理 ...
- Ubuntu16.04Apache负载均衡+集群
mod_proxy ,主代理模块Apache模块用于重定向连接;它允许Apache充当底层应用程序服务器的网关.mod_proxy_http ,它增加了对代理HTTP连接的支持.mod_proxy_b ...
- python中list和dict
字典(Dictionary)是一种映射结构的数据类型,由无序的“键-值对”组成.字典的键必须是不可改变的类型,如:字符串,数字,tuple:值可以为任何python数据类型. 1.新建字典 1 2 3 ...
- mysql批量更新update中的锁表机制
mysql的行锁是通过索引加载的,即行锁是加在索引响应的行上的,要是对应的SQL语句没有走索引,则会全表扫描,行锁则无法实现,取而代之的是表锁. CREATE TABLE SIMPLE_USER( I ...
- 海思3531添加移远EC20 4g模块(转)
源: 海思3531添加移远EC20 4g模块 Hi3798移植4G模块(移远EC20)
- Vue绑定属性 绑定Class 绑定style
<template> <div id="app"> <h2>{{msg}}</h2> <br> <div v-bi ...
- shell编程系列22--shell操作数据库实战之shell脚本与MySQL数据库交互(增删改查)
shell编程系列22--shell操作数据库实战之shell脚本与MySQL数据库交互(增删改查) Shell脚本与MySQL数据库交互(增删改查) # 环境准备:安装mariadb 数据库 [ro ...