动态切换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. vue 使用moment

    1.下载 cnpm i moment --save 2.main.js  挂载 import moment from 'moment'//导入文件 Vue.prototype.$moment = mo ...

  2. Gerrit服务器权限管理

    Gerrit服务器权限管理 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.Gerrit权限概述 1>.对象 Gerrit识别单个或多个人员集合. Gerrit不允许使用单 ...

  3. nginx-location语法匹配优先级

  4. node基础学习——http基础知识-02-http响应数据流

    <一> 发送服务器端响应流 在createServer()方法的参数值回调函数或服务器对象的request事件函数中的第二个参数值为一个http.ServerResponse对象,可以利用 ...

  5. 如何将scratch3.0的作业自动提交到后台数据库

    大家都知道Scratch3.0开发后,默认是可以下载文件到电脑,但是如果是作为商业系统来说,我们需要将作业自动的提交到后台,因此有了这篇文章. 首先,我们来分解下开发步骤: 1.在菜单栏新增一个上传到 ...

  6. windows查看文件MD5值的命令

    今天需要,就记录一下. certutil -hashfile filename MD5 certutil -hashfile filename SHA1 certutil -hashfile file ...

  7. postgres —— 有序集与假象聚集

    有序集 -- 有序集.分组后,按给定顺序排序,再进行计算 SELECT region, percentile_disc(0.5) WITHIN GROUP (order by production) ...

  8. 洛谷 P3605 [USACO17JAN]Promotion Counting晋升者计数

    题目描述 The cows have once again tried to form a startup company, failing to remember from past experie ...

  9. L1141(bfs思想)

    一,看 1,整个方格图其实可以看做是一些不连通的图. 当然图内部必然是联通的. 2,遍历的技巧没什么. 方格图入队的技巧..额,是这样的 int gtid(int x,int y) { return ...

  10. c博客作业01--顺序分支结构

    0.展示PTA总分 1.本章学习总结 1.1 学习内容总结 1.运算符需注意的要点 '/'的左右两边如果均为整型数,其结果也为整型:'%'的左右两边只能为整型数: 优先级:逻辑运算符<关系运算符 ...