动态切换class,主要代码::class="i.themColor" 

<view  v-for="i in htmlJSON" class="column" :class="i.themColor"  >
<view class="uni-flex uni-column line">
<view class="flex-item flex-item-V uni-bg-red">
<view class="flex-item left">
<view class="title">{{i.title}}</view>
<view class="txt">{{i.txt}}</view>
</view>
</view>
</view>
</view> <script>
import common from '../../common/common.js';
export default {
data() {
return {
htmlJSON:common.kdtHomeHtmlJSON
}
},
methods: {
},
mounted() {
}
}
</script> <style lang="scss">
// body
.content{
width: 750upx;
height: 634upx;
} // 内容:
.colorA268D4{
background:#A268D4 url(../../static/images/kdt/icon-test.png) no-repeat 530upx 45upx;
background-size: 125upx;
}
.colorFA5E8A{
background:#FA5E8A url(../../static/images/kdt/icon-.png) no-repeat 530upx 45upx;
background-size: 125upx;
}
.color58C4CC{
background:#58C4CC url(../../static/images/kdt/icon-curriculum.png) no-repeat 530upx 45upx;
background-size: 125upx;
}
.color7E8FEF{
background:#7E8FEF url(../../static/images/kdt/icon-family.png) no-repeat 530upx 45upx;
background-size: 125upx;
}
.column {
width: 702upx;
height: 182upx;
margin:17upx auto;
padding-left: 25upx;
padding-top: 35upx;
line-height: 42upx;
letter-spacing: 4upx;
border-radius: 10upx;
.title{
color: #ffffff;
font-size: 31upx;
}
.txt{
width: 426upx;
font-size: 25upx;
color: #E6E6E6
}
} </style> //commom.js
export default {
kdtHomeHtmlJSON:[{
title:'体测数据录入',
txt:'体测数据现场“录入+上传”,一步到位!',
themColor:'colorA268D4'
},
{
title:'入园师训',
txt:'提高幼师对于体育与运动领域基本知识,基本技能,实践操作能力',
themColor:'colorFA5E8A'
},
{
title:'体能课程',
txt:'提升幼师对于体育与运动领域基本知识,基本技能,实践操作能力',
themColor:'color58C4CC'
},
{
title:'家长工作',
txt:'确保每位家长都能收到孩子的体能成果',
themColor:'color7E8FEF'
}]
}

动态切换style,主要代码: :style="{'background':item.TypeColor}"

<!-- 体测 -->
<view class="block" v-for="itemList in list">
<view class="title">
<view class="title-word">
{{itemList[].TypeName}}
</view>
</view>
<view class="content" v-for="(item,index) in itemList" :key="index">
<!-- 日历选择器 -->
<picker mode="date" :value="item.BookTime" @change="bindDateChange($event,item)">
<view class="book left" v-if="!item.BookTime">
<image src="../../static/images/icon-calendar.png" mode=""></image>
<view class="text">
预约
</view>
</view>
<view class="booked left" v-else >
<text>{{item.BookTimeTxt}}</text>
<image src="../../static/images/icon-calendar.png" mode=""></image>
</view>
</picker>
<!-- 分割西线 -->
<view class="break left" >
<view class="break-line-pe left" :style="{'background': item.TypeColor}"></view>
</view>
<!-- 题目 -->
<view class="message-pe left" :style="{'background': item.TypeColor}">
<view class="message-info nowrap">
{{item.Name}}
</view>
</view>
</view>
<view class="box"></view>
</view> <script>
this.list={
"":[
{
"Id":,
"CreateTime":"2019-01-26T15:05:40.5970000",
"ServiceUnitId":,
"ServiceMetadataId":,
"LikedCount":,
"Type":,
"Status":false,
"ContentId":,
"Name":"森林运动会",
"TypeName":"课程",
"TypeColor":"#68CDD4"
},
Object{...},
Object{...},
Object{...}
],
"":[
Object{...},
Object{...}
],
"":[
Object{...},
Object{...}
]
}
<script>

说明:为节约性能,将 Class 与 Style 的表达式通过 compiler 硬编码到 uni-app 中,支持语法和转换效果如下:

class 支持的语法:

<view :class="{ active: isActive }"></view>
<view class="static" v-bind:class="{ active: isActive, 'text-danger': hasError }"></view
<view class="static" :class="[activeClass, errorClass]"></view>
<view class="static" v-bind:class="[isActive ? activeClass : '', errorClass]"></view>
<view class="static" v-bind:class="[{ active: isActive }, errorClass]"></view>

style 支持的语法:

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

不支持 Vue官方文档:Class 与 Style 绑定 中的 classObject 和 styleObject 语法。

此外还可以用 computed 方法生成 class 或者 style 字符串,插入到页面中,举例说明:

<template>
<!-- 支持 -->
<view class="container" :class="computedClassStr"></view>
<view class="container" :class="{active: isActive}"></view>
<!-- 不支持 -->
<view class="container" :class="computedClassObject"></view>
</template>

动态菜单切换示例

<template>
<scroll-view class="menus">
<view v-for="(menu, index) in menus" :class="[index == currentIndex ? 'menuActive' : '']">{{menu}}</view>
</scroll-view>
</template> <script>
export default {
data: {
currentIndex : ,
menus : [
'新闻', '汽车', '读书'
]
},
onLoad:function(options){
console.log("onLoad");
},
onHide:function(){
console.log("onHide");
},
onShow:function(){
console.log("onShow");
}
}
</script> <style>
.menus{width:700px; margin: auto; padding:20px 0px;}
.menus view{padding:8px; line-height:20px; font:38px; float:left;}
.menuActive{color:#;}
</style>

uni-app v-for循环遍历 动态切换class、动态切换style的更多相关文章

  1. 编写高质量代码改善C#程序的157个建议[动态数组、循环遍历、对象集合初始化]

    前言   软件开发过程中,不可避免会用到集合,C#中的集合表现为数组和若干集合类.不管是数组还是集合类,它们都有各自的优缺点.如何使用好集合是我们在开发过程中必须掌握的技巧.不要小看这些技巧,一旦在开 ...

  2. 动态二维数组赋值及for循环遍历和toString遍历

    package com.Summer_0421.cn; import java.util.Arrays; /** * @author Summer * 动态二维数组赋值及for循环遍历和toStrin ...

  3. C#程序编写高质量代码改善的157个建议【16-19】[动态数组、循环遍历、对象集合初始化]

    前言   软件开发过程中,不可避免会用到集合,C#中的集合表现为数组和若干集合类.不管是数组还是集合类,它们都有各自的优缺点.如何使用好集合是我们在开发过程中必须掌握的技巧.不要小看这些技巧,一旦在开 ...

  4. Layui之动态循环遍历出的富文本编辑器显示

    这篇记得是工作中的例子 描述: 平常的富文本显示都是根据静态的html获取id来显示,比如: <textarea class="layui-textarea" id=&quo ...

  5. for 循环遍历数据,根据不同的条件判断动态渲染页面!

    整体的逻辑为:for 循环遍历出数据,在for 循环里判断,根据不同的条件渲染 一.html页面结构 二.css就不再写了 三.JS逻辑代码 var listGroup='' ;k<data.i ...

  6. php中的循环遍历 foreach list each

    foreach语句遍历数组foreach语句用于循环遍历数组,每进行一次循环,当前数组元素的值就会被赋值给变量value(也可以是其它变量),数组指针会逐一的移动. 代码示例: foreach($ar ...

  7. php用压栈的方式,循环遍历无限级别的数组(非递归方法)

    php用压栈的方式,循环遍历无限级别的数组(非递归方法) 好久不写非递归遍历无限级分类...瞎猫碰到死老鼠,发刚才写的1段代码,压栈的方式遍历php无限分类的数组... php压栈的方式遍历无限级别数 ...

  8. Objective-C 高性能的循环遍历 forin - NSEnumerator - 枚举 优化

    Cocoa编程的一个通常的任务是要去循环遍历一个对象的集合  (例如,一个 NSArray, NSSet 或者是 NSDictionary). 这个看似简单的问题有广泛数量的解决方案,它们中的许多不乏 ...

  9. yii2通过foreach循环遍历在一个用户组中取出id去另一表里查寻信息并且带着信息合并原数组信息---案例

    yii2通过foreach循环遍历在一个用户组中取出id去另一表里查寻信息并且带着信息合并元数组信息---案例 public function actionRandomLists(){ //查询到了所 ...

  10. HashMap循环遍历方式及其性能对比(zhuan)

    http://www.trinea.cn/android/hashmap-loop-performance/ ********************************************* ...

随机推荐

  1. SWD烧录/仿真方式

    单片机在烧写/仿真的时候具有一种方式叫做SWD,这种方式只用到两根线SWDIO,SWCLK.一般SWD和JTAG中的JTMS和JTCK共用的.由于线少,所以使用非常方便,但是速率相对较低. 在接线时, ...

  2. C# CustomValidator

    当各种验证控件的验证类型都不能满足需要时可以使用CustomValidator验证控件,通过自定义验证函数来验证.直接看例子 <%@ Page Language="C#" A ...

  3. .NET 使用 VLC 播放视频

    使用 VLC 播放监控有几个月了,现在是多个项目中都有用到.在使用的过程中也有一些细节供大家参考. 一.对 VLC 的了解 VLC 是一个开源的跨平台多媒体播放器及框架. VLC 官方出的有播放器.编 ...

  4. 文件上传相关报错: The current request is not a multipart request或is a MultipartResolver configured?

    1:from中涉及到图片上传的就要用post提交方式.否则就会报这个错误. 2:第一中:在jsp页面的<head></head>标签里面加上<meta http-equi ...

  5. mybatis的注意事项一

    在UserMapper.xml文件中写resultType="cn.smbms.dao.pojo.User"返回类型的全路径是不是很长,而且也比较不美观:不便于后期项目的维护. 解 ...

  6. 使用Simian进行重复代码检测

    一.概述 Simian是一个可跨平台使用的重复代码检测工具,有商用和免费两种使用渠道,官方网址为:http://www.harukizaemon.com/simian/installation.htm ...

  7. 关于原生js的节点兼容性

    关于节点的兼容性: 1:获取元素的子节点 a: childNodes:获取元素的子节点,空文本,非空文本,注释,获取的比较全面, 如果只是想获取元素的子节点,请用(children) b:     c ...

  8. am335x system upgrade kernel tf(五)

    1      Scope of Document This document describes TF hardware design 2      Requiremen 2.1     Functi ...

  9. 过滤器的API

    1.API a.生命周期(和servletcontext相似): (1)创建:服务器启动的时候创建(执行init方法). (2)销毁:服务器关闭的时候销毁(执行destory方法). b.filter ...

  10. ShardingSphere初探1 -- 概览

    知道这个框架是通过一期QQ课堂 https://shardingsphere.apache.org 官网 https://github.com/apache/incubator-shardingsph ...