class、style的绑定
1.在 v-bind 用于 class 和 style 时, Vue.js 专门增强了它。表达式的结果类型除了字符串之外,还可以是对象或数组
2.绑定css
2.1对象绑定
2.1.1绑对象格式参数
dom
div class="static"
     v-bind:class="{ active: isActive, 'text-danger': hasError }">
</div>
vue
data: {
  isActive: true,
  hasError: false
}
2.1.2直接绑对象
dom
<div v-bind:class="classObject"></div>
vue
data: {
  classObject: {
    active: true,
    'text-danger': false
  }
}
2.1.3返回对象的计算属性
dom
div v-bind:class="classObject"></div>
vue
data: {
  isActive: true,
  error: null
},
computed: {
  classObject: function () {
    return {
      active: this.isActive && !this.error,
      'text-danger': this.error && this.error.type === 'fatal',
    }
  }
}
2.1.绑定数组
dom
<div v-bind:class="[activeClass, errorClass]">
vue:
data: {
  activeClass: 'active',
  errorClass: 'text-danger'
}
2.2绑定三元表达式
<div v-bind:class="[isActive ? activeClass : '', errorClass]">
2.3绑定数组对象
<div v-bind:class="[{ active: isActive }, errorClass]">
3.绑定style
3.1对象形式绑定
dom
<div v-bind:style="{ color: activeColor, fontSize: fontSize + 'px' }"></div>
vue
<div v-bind:style="{ color: activeColor, fontSize: fontSize + 'px' }"></div>
3.2对象绑定
dom
<div v-bind:style="styleObject"></div>
vue
data: {
  styleObject: {
    color: 'red',
    fontSize: '13px'
  }
}

vue-绑定style、css的更多相关文章

  1. vue - 绑定css、style

    1.绑定html css1.1对象语法: 传给 v-bind:class 一个对象,以动态地切换 class <div v-bind:class="{ active: isActive ...

  2. 黑马vue---17、vue中通过属性绑定绑定style行内样式

    黑马vue---17.vue中通过属性绑定绑定style行内样式 一.总结 一句话总结: 如果属性名中带有短线必须加引号,比如: h1StyleObj: { color: 'red', 'font-s ...

  3. vue绑定属性、绑定class及绑定style

    1.绑定属性  v-bind 或者 : 例如:<img :src="pic_src" /> <template> <div id="app& ...

  4. SFC style CSS variable injection

    摘要 在单文件组件样式中支持使用组件状态驱动的 CSS 变量( CSS 自定义属性). 基础示例 <template> <div class="text"> ...

  5. Vue过渡效果之CSS过渡

    前面的话 Vue 在插入.更新或者移除 DOM 时,提供多种不同方式的应用过渡效果.本文将从CSS过渡transition.CSS动画animation及配合使用第三方CSS动画库(如animate. ...

  6. vue 绑定样式的几种方式

    vue 绑定样式 对象语法 1.v-bind:class设置一个对象,动态切换class <div :class="{'active':isActive}">xxx&l ...

  7. Vue之动态绑定CSS样式

    demo.html <!DOCTYPE html> <html lang="en" xmlns:v-bind="http://www.w3.org/19 ...

  8. $Django 路飞之小知识回顾,Vue之样式element-ui,Vue绑定图片--mounted页面挂载--路由携带参数

    一 小知识回顾 1 级联删除问题 2 一张表关联多个表,比如有manytomanyfileds forignkey,基于对象查询存在的问题:反向查询的时候  表名小写_set.all()不知是哪个字段 ...

  9. vue中引入css文件

    两种方式引入css文件,一种是直接在main.js中引入(也可以在其他的.vue文件中的<script></script>标签中),即下面这种写法: import 'eleme ...

  10. <转载> VUE项目中CSS管理

    vue的scoped 在vue项目中,当 .vue文件中 <style> 标签有 *scoped 属性时,它的 CSS 只作用于当前组件中的元素,很好的实现了样式私有化的目的. 使用sco ...

随机推荐

  1. Linux下查看文件编码,文件编码格式转换和文件名编码转换

    linux相关   2008-10-07 10:46   阅读1392   评论0   字号: 大大  中中  小小  如果你需要在Linux中 操作windows下的文件,那么你可能会经常遇到文件编 ...

  2. System.Threading.Thread的使用及传递参数等总结

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...

  3. 【C#】截取字符串

    几个经常用到的字符串的截取 string str="123abc456"; int i=3; 1 取字符串的前i个字符 str=str.Substring(0,i); // or ...

  4. OC官方文档翻译-Working-with-Protocols-协议的使用

    查看全部文档翻译,请浏览https://github.com/L1l1thLY/Programming-with-Objective-C-in-Chinese,blog仅收录本人翻译的两章. 简述 在 ...

  5. ASP.NET对象

    ASP.NET有五个基本的常用对象 一张图胜过前言万语 ASP.NET对象重头戏 对象名    解释 属性 方法 例子 Request 获取客户端数据信息 1.UserAgent:用来获取客户端浏览器 ...

  6. 多线程中wait、notify理解

    实在惭愧,java开发多年,多线程运用一直不多,该知识点理解也不够,不怎么会用.赶上使用多线程 生产者.消费者模式,学习下该知识点. synchronized  获取锁 wait 阻塞本线程,释放对象 ...

  7. MySQL常用配置和性能压力测试:MySQL系列之十五

    一.MySQL常用配置 以下所有配置参数以32G内存的服务器为基 1.打开独立的表空间 innodb_file_per_table = 1 2.MySQL服务所允许的同时会话数的上限,默认为151,经 ...

  8. JPA规范基础 ppt教程

    https://wenku.baidu.com/view/5ca6ce6a1eb91a37f1115cee.html

  9. object.wait为什么要和synchronized一块使用

    Object.wait 中JDK提供的doc文档 Causes the current thread to wait until another thread invokes the notify() ...

  10. 010 Regular Expression Matching 正则表达式匹配

    Implement regular expression matching with support for '.' and '*'.'.' Matches any single character. ...