美文网首页
v-bind:style样式绑定

v-bind:style样式绑定

作者: 新篇章 | 来源:发表于2018-03-05 13:42 被阅读0次

一、直接添加样式属性

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Vue 测试实例 - 菜鸟教程(runoob.com)</title>
<script src="https://cdn.bootcss.com/vue/2.2.2/vue.min.js"></script>
</head>
<body>
<div id="app">
    <div v-bind:style="{ color: activeColor, fontSize: fontSize + 'px',background:'red' }">内联样式</div>
</div>

<script>
new Vue({
  el: '#app',
  data: {
    activeColor: 'green',
    fontSize: 30
  }
})
</script>
</body>
</html>

二、绑定到样式对象

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Vue 测试实例 - 菜鸟教程(runoob.com)</title>
<script src="https://cdn.bootcss.com/vue/2.2.2/vue.min.js"></script>
</head>
<body>
<div id="app">
  <div v-bind:style="styleObject">绑定样式对象</div>
</div>

<script>
new Vue({
  el: '#app',
  data: {
    styleObject: {
      color: 'green',
      fontSize: '30px',
      background:'red'
    }
  }
})
</script>
</body>
</html>

三、多样式绑定

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Vue 测试实例 - 菜鸟教程(runoob.com)</title>
<script src="https://cdn.bootcss.com/vue/2.2.2/vue.min.js"></script>
</head>
<body>
<div id="app">
  <div v-bind:style="[baseStyles, overridingStyles]">多样式绑定</div>
</div>

<script>
new Vue({
  el: '#app',
  data: {
    baseStyles: {
      color: 'green',
      fontSize: '30px',
      background:'red'
    },
    overridingStyles: {
      'font-weight': 'bold'
    }
  }
})
</script>
</body>
</html>

相关文章

  • Vue绑定对象和数组

    class列表和内联样式style都是属性,所以可以使用v-bind动态绑定 v-bind:class="{...

  • 【Vue】 绑定Class与Style && 条件渲染

    操作元素的class列表和内联样式Style是数据绑定的常见需求,通过 v-bind绑定Class列表与内联样式S...

  • (9)打鸡儿教你Vue.js

    样式绑定 设置元素的样式用 v-bind 来设置样式属性class 与 style 是 HTML 元素的属性 v-...

  • Vue.js教程_4

    操作元素的class列表和内联样式的数据绑定:使用v-bind和style与class结合。v-bind也可与操作...

  • Class与Style绑定

    1.绑定HTML Class 2.绑定内联样式 v-bind:style会自动为某些CSS属性添加特定前缀,2.3...

  • v-bind:style样式绑定

    一、直接添加样式属性 二、绑定到样式对象 三、多样式绑定

  • 6 动态绑定属性

    v-bind基本用法 v-bind 绑定style 动态绑定class对象语法···...

  • 样式绑定

    class与style是HTML元素的属性,用于设置元素的样式,我们可以用v-bind来设置样式属性。 绑定HTM...

  • Vue基础指令

    Vue循环指令 Vue绑定指令: v-bind:style,v-bind:class: v-model双向数据绑定...

  • Vue.js从0到1:v-bind指令

    Vue.js从0到1:v-bind 指令 1. 代码演示 v-bind :绑定 : 绑定class、绑定style...

网友评论

      本文标题:v-bind:style样式绑定

      本文链接:https://www.haomeiwen.com/subject/eochfftx.html