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. hdu1069

    #include <iostream> #include <algorithm> #include <cstring> using namespace std; c ...

  2. vue中computed与methods的异同

    在vue.js中,有methods和computed两种方式来动态当作方法来用的 如下: 两种方式在这种情况下的结果是一样的 写法上的区别是computed计算属性的方式在用属性时不用加(),而met ...

  3. SuperSocket框架中BinaryRequestInfo协议的使用

    一.开发环境 1.Windows 10 企业版 64位 2.Microsoft Visual Studio 2017 企业版 二.项目开始 1.新建控制台程序,项目名称“BinarySuperSock ...

  4. pure css简单组件,借鉴bootstrap

    <!doctype html> <html> <head> <meta http-equiv="Content-type" content ...

  5. python drift

    install dependency(optional):(本文来自 不才b_d 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/sinat_36184075/arti ...

  6. php soap连接https的wsdl报错SOAP-ERROR: Parsing WSDL:Couldn't load from

    转发:https://blog.csdn.net/keyunq/article/details/51804728 SOAP-ERROR: Parsing WSDL:Couldn’t load from ...

  7. 2017BAPC初赛A(思维,无序图,向量)

    #include<bits/stdc++.h>using namespace std;string goods,sister[100010];int x,m;unordered_map&l ...

  8. 洛谷P4332 [SHOI2014]三叉神经树(LCT)

    传送门 FlashHu大佬太强啦%%% 首先,我们可以根据每一个点的权值为$1$的儿子的个数把每个点记为$0~3$,表示这一个点的点权 先考虑一下暴力的过程,假设从$0$变为$1$,先更改一个叶子结点 ...

  9. c#之 quartz的学习

    目录: 一. Quartz的API 二.Trigger 的使用 三.使用 JobDataMap 来往Job中传值 四. Calendars 五.SimpleTrigger 六.CronTrigger ...

  10. 洛谷 P1547 Out of Hay (最小生成树)

    嗯... 题目链接:https://www.luogu.org/problemnew/show/P1547 思路: 嗯...既然题中已经说了是最小生成树,那么是需要在最小生成树的模板上稍作修改即可.要 ...