1, 绑定html class

1), 直接绑定

   <div>
isActive 为true, 则显示 active css
<p v-bind:class="{active: isActive}">哈哈</p>
</div>
data() {
return {
isActive: true,
}
},

2), 多个值可通过对象的方式绑定:

<!--可以绑定为对象-->
<div>
<p v-bind:class="styleObj"> 哈哈 </p>
</div>
data() {
return {
styleObj: {
active: true,
'demo': true
}
}
},

3), 通过computed 绑定:

<div>
<p v-bind:class="styleObj1"> 哈哈哈啊</p>
</div>
computed: {
styleObj1() {
return {
"active": this.isActive,
"demo": this.isDemo
}
}
}

4) , 数组语法

<!--使用表达式绑定-->
<ul>
<li :class="[{active: index % 2 == 0}, 'info-' + id]" v-for="(name, index) in names ">{{ name }}</li>
</ul>
data() {
return {
isActive: true,
isDemo: true,
styleObj: {
active: true,
'demo': true
},
id: ,
demo1: "demo11",
demo2: "demo22",
names: ['wenbronk', 'vini', 'lisa'],
stob: {
color: "red",
fontSize: "24px"
}
}
},

5), 绑定内联样式

<!--绑定内联样式-->
<div>
<p :style="stob"> 内敛样式 </p>
</div>
stob: {
color: "red",
fontSize: "24px"
}

vue-03-style与class的更多相关文章

  1. 练习vue(class,style属性)

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  2. 深入理解VUE样式style层次分析

    刚开始使用vue的时候容易被里面的样式搞懵: 样式可以在main.js中引入,在模块js文件中引入,在组件中的style标签引入,在组件中的script标签引入,还可以在index.html的body ...

  3. 013——VUE中多种方式使用VUE控制style样式属性

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  4. Vue.js style(内联样式)

    Vue.js style(内联样式) 我们可以在 v-bind:style 直接设置样式: <div id="app"> <div v-bind:style=&q ...

  5. Vue 03

    目录 组件 组件的分类 组件的特点 组件的使用 组件传参-父传子 组件传参-子传父 组件 组件就是html, css和js文件的集合体, 实现对代码的复用, 组件就是vue对象 组件的分类 根组件 & ...

  6. Vue 设置style样式

    1.直接添加行内样式 2.通过绑定设置style样式 3.将vue的属性设置为样式 4将多个vue属性设置为样式 <div id="box"> <!--直接添加样 ...

  7. Vue 设置style属性

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. vue中style下scope的使用和坑

    在vue组件中,为了使样式私有化(模块化),不对全局造成污染,可以在style标签上添加scoped属性以表示它的只属于当下的模块,这是一个非常好的举措,但是为什么要慎用呢?因为在我们需要修改公共组件 ...

  9. VUE中 style scoped 修改原有样式

    作用域CSS 当<style>标记具有该scoped属性时,其CSS将仅应用于当前组件的元素.这类似于Shadow DOM中的样式封装.它有一些警告,但不需要任何polyfill.通过使用 ...

  10. Vue 的style绑定显示background-image

    data () { return { img: require('你的json资源路径') } } :style="{backgroundImage: 'url(' + img + ')'} ...

随机推荐

  1. javaweb开发.调试

    一.快速调试一个类 1.类里面写public static void main(String[] args) throws Exception{}方法 2.该类上右键->Run As->J ...

  2. [快速幂][NOIP2012]转圈游戏

    转圈游戏 题目描述 n 个小伙伴(编号从 0 到 n-1)围坐一圈玩游戏.按照顺时针方向给 n 个位置编号,从0 到 n-1.最初,第 0 号小伙伴在第 0 号位置,第 1 号小伙伴在第 1 号位置, ...

  3. jquery 表单校验

    <link type="text/css" href="<%=basepath%>css/form/validate.css" rel=&qu ...

  4. Python 多进程编程之fork()

    Python实现多进程可以用系统fork()方法和python的multiprocessing类 1,fork()方法是Unix/Linux操作系统提供的,在python的os模块中自带fork(). ...

  5. 2018上IEC计算机高级语言(C)作业 第1次作业

    1.经过这几周的学习,总结一下学习的心得与体会.(不少于100字:10分) 学习c语言已经一个学期了,刚开始学习的时候老是感觉力不从心.虽然认真听课了, 但是并不能理解它.这种情况到了后来才有所改变. ...

  6. SpringBoot2.x配置JsonRedisSerializer

    @Configurationpublic class SpringCacheRedisConfig { @Bean public RedisCacheManager cacheManager(Redi ...

  7. tensorflow学习之(一)预测一条直线y = 0.1x + 0.3

    #预测一条y = 0.1x + 0.3的直线 import tensorflow as tf import numpy as np #科学计算模块 ''' tf.random_normal([784, ...

  8. docker 技术

    利用docker打包一个sshd的服务 准备环境 安装docker     修改主机名与hosts解析     echo '10.0.0.11 docker01'     参考文档:https://m ...

  9. Log4J日志整合及配置详解

    Log4j有三个主要的组件:Loggers(记录器),Appenders (输出源)和Layouts(布局).这里可简单理解为日志类别,日志要输出的地方和日志以何种形式输出.综合使用这三个组件可以轻松 ...

  10. kei下无法跳转到函数的定义处

    1 勾选“option for target”----“output”----"Browse information" 2 重新编译整个工程, 执行上面两个步骤就可以跳转了.