微信小程序提供了比较便捷的语法,使我们能够快速地动态绑定class
用法:
在一个标签的class里添加{{}}模板语法,模板里面是一个三元判别式,其中表达式一般引用data中的属性,表达式返回true或者false,A,B是class名,按照三元判别式的逻辑引用A或B 。
PS:
一个简单的例子:
index.wxml
类给按钮添加了蓝色边框,根据data中的属性isRed,选择按钮的背景色
index.js
isRed属性设置成true
【小程序 动态绑定class】
文章插图
//index.js//获取应用实例const app = getApp()Page({data: {motto: 'Hello World',userInfo: {},hasUserInfo: false,canIUse: wx.canIUse('button.open-type.getUserInfo'),isRed: true},})
index.wxss
/**index.wxss**/.border {border: 10rpx solid blue;margin-top: 50rpx;}.red {background-color: red;}.green {background-color: green;}
最终效果
- 脚背疼痛是什么原因 脚背疼痛是什么原因
- 蜡笔小新游戏可以变蟑螂的是第几部?
- 小区有人养鸡扰民,报警警察该管吗?
- 小程序连接MYSQL实现增删改查
- 微信 小程序 在电脑PC端无法加载的解决办法。电脑微信小程序打不开是怎么回事?
- 喜怒不形于色的意思 喜怒不形于色是啥意思
- 肾炎症状有哪些 肾炎症状有哪些方面
- 女短裤 女短裤的裁剪方法
- 什么是模拟上课 什么是模拟上课稿
- 程序员为什么能月薪5万 ?看完就知道了