微信小程序/uniapp:class和style不生效的问题

非常重要:小程序端不支持 classObject 和 styleObject 语法。

文档:https://uniapp.dcloud.net.cn/tutorial/vue-basics.html#class-与-style-绑定

目录

对象语法

html 复制代码
<!-- class -->
<view class="static" :class="{ active: isActive}">111</view>

<!-- style -->
<view :style="{ color: activeColor, fontSize: fontSize + 'px' }">333</view>

数组语法

html 复制代码
<!-- class -->
<view class="static" :class="['activeClass', 'errorClass']">111</view>

<!-- style -->
<view :style="[{ color: activeColor, fontSize: fontSize + 'px' }]">444</view>

字符串语法

html 复制代码
<!-- class -->
<view class="static" :class="computedClassStr">111</view>

<!-- style -->
<view :style="computedClassStr">444</view>

computed

html 复制代码
 <!-- 支持 -->
<view class="container" :class="computedClassStr"></view>
<view class="container" :class="{active: isActive}"></view>

<!-- 不支持 -->
<view class="container" :class="computedClassObject"></view>

其他方案

使用第三方库classnames,来处理类名,可以将ClassObject转为ClassStr

具体用法可以参看:https://pengshiyu.blog.csdn.net/article/details/134287806

相关推荐
小徐_23331 天前
uni-app vue3 也能使用 Echarts?Wot Starter 是这样做的!
前端·uni-app·echarts
iOS阿玮1 天前
永远不要站在用户的对立面,挑战大众的公知。
uni-app·app·apple
xw51 天前
uni-app中v-if使用”异常”
前端·uni-app
!win !1 天前
uni-app中v-if使用”异常”
前端·uni-app
Emma歌小白1 天前
如何首次运行小程序后端
微信小程序
赣州云智科技的技术铺子1 天前
【一步步开发AI运动APP】十二、自定义扩展新运动项目1
微信小程序·小程序·云开发·智能小程序
2501_915918411 天前
iOS 上架全流程指南 iOS 应用发布步骤、App Store 上架流程、uni-app 打包上传 ipa 与审核实战经验分享
android·ios·小程序·uni-app·cocoa·iphone·webview
00后程序员张1 天前
iOS App 混淆与加固对比 源码混淆与ipa文件混淆的区别、iOS代码保护与应用安全场景最佳实践
android·安全·ios·小程序·uni-app·iphone·webview
破无差2 天前
《赛事报名系统小程序》
小程序·html·uniapp
00后程序员张2 天前
详细解析苹果iOS应用上架到App Store的完整步骤与指南
android·ios·小程序·https·uni-app·iphone·webview