参考uni文档:https://uniapp.dcloud.io/use?id=class-%E4%B8%8E-style-%E7%BB%91%E5%AE%9A

参考vue文档:https://cn.vuejs.org/v2/guide/class-and-style.html#%E7%BB%91%E5%AE%9A%E5%86%85%E8%81%94%E6%A0%B7%E5%BC%8F

Class类和Style通过值快速切换

uni官方和vue文档有不明之出,官方已指出

 <template>
<view class="content f f-wrap"> <image class="logo" src="../../static/image/myHover.png" @click="tap"></image> <!--
前:样式
后:控制:显示/隐藏
--> <!-- 单类 -->
<view :class="{ active: isActive }">111</view> <!-- 对象 -->
<view class="static" :class="{ active: isActive, 'text-danger': hasError }">222</view> <!-- 数组 -->
<view class="static" :class="[activeClass, errorClass]">333</view> <!-- 条件 -->
<view class="static" v-bind:class="[isActive ? activeClass : '', errorClass]">444</view> <!-- 数组+对象 -->
<view class="static" v-bind:class="[{ activeGrey: isActive }, errorClass]">555</view> <!-- 执行类 -->
<view class="container" :class="computedClassStr"></view>
<view class="container" :class="{activeGrey: isActive}">9999</view> <!-- style支持的类 -->
<view v-bind:style="{ color: activeColor, fontSize: fontSize + 'px' }">666</view>
<view v-bind:style="[{ color: activeColor, fontSize: fontSize + 'px' }]">777</view> </view>
</template> <script> export default {
data() {
return {
title: 'Hello', // 单激活类
isActive: true,
hasError: true, // 多种激活类
activeClass: {
'active': false,
'text-danger': true
},
errorClass: {
'active': true,
'text-danger': false
}, activeColor:true,
fontSize:30
}
},
onLoad() {
this.fetchData()
console.log('页面加载')
},
onShow() {
console.log('页面显示')
},
onReady() {
console.log('页面初次显示')
},
onHide() {
console.log('页面隐藏')
},
onUnload() {
console.log('页面卸载')
},
onBackPress() {
console.log('页面返回...')
},
onShareAppMessage() {
console.log('分享!')
},
onReachBottom() {
console.log('下拉加载...')
},
onPageScroll() {
console.log('页面滚动...')
},
onPullDownRefresh() {
console.log('上拉刷新...')
uni.stopPullDownRefresh();
}, // #ifdef APP-PLUS
onNavigationBarButtonTap() { },
// #endif methods: {
tap(e) {
console.log('tap点击!', e);
},
fetchData() {
console.log('拉取数据...');
},
computedClassStr() {
return this.isActive ? 'actives' : 'active'
}
}
}
</script> <style lang="scss">
.active {
color: #f00;
} .activeGrey {
color: #aaa;
} .text-danger {
color: #f0f;
font-weight: bold;
} .f {
display: flex;
} .f-wrap {
flex-wrap: wrap;
}
</style>

通过模板(template)端控制模板

通过控制端(JS)来控制行为

通过(CSS)显示端进行显示

uni-app - Class 与 Style 绑定的更多相关文章

  1. 关于vue.js中class与style绑定的学习

    练习代码: html: <!DOCTYPE html><html lang="en"><head> <meta charset=" ...

  2. 前端MVC Vue2学习总结(三)——模板语法、过滤器、计算属性、观察者、Class 与 Style 绑定

    Vue.js 使用了基于 HTML 的模版语法,允许开发者声明式地将 DOM 绑定至底层 Vue 实例的数据.所有 Vue.js 的模板都是合法的 HTML ,所以能被遵循规范的浏览器和 HTML 解 ...

  3. Vue学习4:class与style绑定

    说明:有些部分我只是相当于做一个学习笔记,加强记忆之用.所以可能阅读性不是那么强.如果有参考我这类博客的人,那么请见谅. 代码如下: <!DOCTYPE html> <html la ...

  4. Vue中计算属性与class,style绑定

    var vm=new Vue({ el:'#app', data:{ a:2, }, computed:{ //这里的b是计算属性:默认getter b:{ get:function(){ retur ...

  5. vue学习笔记(三)class和style绑定

    前言 通过上一章的学习vue学习笔记(二)vue的生命周期和钩子函数,我们已经更近一步的知道了关于vue的一些知识,本篇博客将进一步探讨vue其它方面的内容,vue中关于class和style绑定,关 ...

  6. 【Vue】Vue框架常用知识点 Vue的模板语法、计算属性与侦听器、条件渲染、列表渲染、Class与Style绑定介绍与基本的用法

    Vue框架常用知识点 文章目录 Vue框架常用知识点 知识点解释 第一个vue应用 模板语法 计算属性与侦听器 条件渲染.列表渲染.Class与Style绑定 知识点解释 vue框架知识体系 [1]基 ...

  7. Vue#Class 与 Style 绑定

    绑定HTMLCLASS 在我没看这之前,我觉得要写绑定class ,应该像绑定数据一样这么写 class ={{class-a}} 看官方教程时,不推荐这么写,推荐这样 v-bind:class=&q ...

  8. Vue中class与style绑定

    gitHub地址:https://github.com/lily1010/vue_learn/tree/master/lesson07 一 用对象的方法绑定class 很简单,举个栗子: <!D ...

  9. Vue.2.0.5-Class 与 Style 绑定

    Class 与 Style 绑定 数据绑定一个常见需求是操作元素的 class 列表和它的内联样式.因为它们都是属性 ,我们可以用v-bind 处理它们:只需要计算出表达式最终的字符串.不过,字符串拼 ...

  10. Knockout.Js官网学习(style绑定、attr绑定)

    Style绑定 style绑定是添加或删除一个或多个DOM元素上的style值.比如当数字变成负数时高亮显示,或者根据数字显示对应宽度的Bar.(注:如果你不是应用style值而是应用CSS clas ...

随机推荐

  1. windows命令行快捷操作

    net use \\ip\ipc$ " " /user:" " 建立IPC空链接 net use \\ip\ipc$ "密码" /user: ...

  2. JTAG接线描述

    http://www.dzsc.com/data/html/2008-12-23/75397.html JTAG测试信号由下面5个信号组成. TRST:测试复位输入信号,测试接口初始化 TCK:测试时 ...

  3. Spring事务传播机制与隔离级别(转)

    Spring事务传播机制与隔离级别 博客分类: Spring   转自:http://blog.csdn.net/edward0830ly/article/details/7569954 (写的不错) ...

  4. 最快的BT软件rtorrent Step by Step指南

    原文地址:http://forum.ubuntu.org.cn/viewtopic.php?t=165069 rtorrent是linux下最快的bt下载软件,由于支持DHT网络,可以很好的于迅雷和B ...

  5. 高手写的“iOS 的多核编程和内存管理”

    原文地址:http://anxonli.iteye.com/blog/1097777 多核运算 在iOS中concurrency编程的框架就是GCD(Grand Central Dispatch), ...

  6. 【docker-compose】使用docker-compose部署运行spring boot+mysql 【处理容器的时区问题】【详解】【福利:使用docker-compose构建 wordpress+mysql】

    ==================================================================================================== ...

  7. rman多通道全备份脚本

     run{ allocate channel d1 type disk; allocate channel d2 type disk; allocate channel d3 type disk; ...

  8. Windows下编译memcached-1.4.5(32bit和64bit)

    1.简介 Memcached 是一个高性能的分布式内存对象缓存系统.它通过将数据缓存在内存中来减少对数据库和文件系统的访问,减轻数据库及操作系统的负担,提高应用系统的速度. 目前已经很多系统应用了me ...

  9. velocity.properties配置说明

    1.Runtime  Log runtime.log  =  velocity.log 用以指定 Velocity 运行时日志文件的路劲和日志文件名,如不是全限定的绝对路径,系统会认为想对于 当前目录 ...

  10. CASpringAnimation的使用

    CASpringAnimation的使用 效果 源码 https://github.com/YouXianMing/Animations // // CASpringAnimationControll ...