美文网首页
vue 的 class 与 style 使用

vue 的 class 与 style 使用

作者: 云龙789 | 来源:发表于2019-01-24 17:44 被阅读3次

使用对象的语法,键对应的就是实际的 calss 值,值对应的是 true 或 false
使用数组的语法,值对应的是 vue data 里面的此值对应的值
style 就相当于是直接在这里写了 style

<html>
<head>
    <meta charset="utf-8">
    <title>Vue class与style测试</title>
    <script src="https://cdn.bootcss.com/vue/1.0.14/vue.min.js"></script>
    <style>
        .red {
            background: red;
            width: 100px;
            height: 100px;
        }
        .green {
            background: green;
            width: 100px;
            height: 100px;
        }
    </style>
</head>
<body>

<div id="app">
    <p>对象语法</p>
    <div v-bind:class="{red:true}">显示红色区块</div>
    <div v-bind:class="{red:false}">不显示</div>
    <div v-bind:class="{red:hide}">值是变量</div>

    <p>数组语法</p>
    <div v-bind:class="[green_color]">不显示</div>
    <p>style 测试</p>
    <div v-bind:style="styleObject"></div>
</div>
<script>
    new Vue({
        el: '#app',
        data: {
            hide:false,
            green_color:'green',
            styleObject: {
                background: 'blue',
                fontSize: '13px',
                height:'100px',
                width:'100px',

            }
        }
    });
</script>
</body>
</html>

相关文章

  • vue 的 class 与 style 使用

    官网-Class 与 Style 绑定 使用对象的语法,键对应的就是实际的 calss 值,值对应的是 true ...

  • mpvue下不同标签页样式的改变

    首先请通读官方文档vue官方文档:Class 与 Style 绑定mpvue官网手册:class-style部分 ...

  • vue:样式绑定

    Vue.js 样式绑定 Vue.js class class 与 style 是 HTML 元素的属性,用于设置元...

  • vue.js学习笔记四

    Vue.js 样式绑定Vue.js class class 与 style 是 HTML 元素的属性,用于设置元素...

  • Vue2.0系列(二、vue基本指令)

    今天主要vue的使用v-if,v-for,v-model,数据双向绑定,处理表单和选框,class与style的常...

  • Vue入门:v-bind

    本篇为Vue的基础篇,主要关于 v-bind: class与style的动态绑定。 1. 绑定 class 的几种...

  • Vue.js 样式绑定

    Vue.js class class 与 style 是 HTML 元素的属性,用于设置元素的样式,我们可以用 v...

  • Vue class与style绑定

    理解在应用界面中, 某个(些)元素的样式是变化的class/style绑定就是专门用来实现动态样式效果的技术 cl...

  • vue Class与Style绑定

    操作元素的 class 列表和内联样式是数据绑定的一个常见需求。因为它们都是属性,所以我们可以用 v-bind 处...

  • Vue class与style绑定

    Class 与 Style 绑定 数据绑定的一个常见需求是操作元素的 class 列表和它的内联样式。因为它们都是...

网友评论

      本文标题:vue 的 class 与 style 使用

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