Vue 使用v-bind:style 绑定样式

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    </head>
    <body>
        <div id="app">
            <div v-bind:style="{ color: activeColor, fontSize: fontSize + ‘px‘ }">好好学习</div>
            <div v-bind:style="styleObject">天天向上</div>
        </div>
    </body>
    <script>
        var vm = new Vue({
            el: ‘#app‘,
            data: {
                activeColor: ‘blue‘,
                fontSize: 30,
                styleObject: {
                    color: ‘green‘,
                    fontSize: ‘50px‘
                }
            }
        })
    </script>
</html>

效果:

原文地址:https://www.cnblogs.com/nongzihong/p/10682583.html

时间: 2024-07-29 23:39:28

Vue 使用v-bind:style 绑定样式的相关文章

Vue.js Class与Style绑定

Class与Style绑定 对于数据绑定,一个常见的需求是操作元素的 class 列表和它的内联样式.因为它们都是属性,我们可以用 v-bind 来处理它们:只需要计算出表达式最终的字符串. 不过,字符串拼接麻烦又易错,因此,在 v-bind 用于 class 和 style 时,Vue.js 专门增强了它.表达式的结果类型除了字符串以外,还可以是对象或数组. 绑定HTML Class 1.对象语法 我们可以传给 v-bind:class 一个对象,以动态地切换 class <div v-bin

Vue中Class与Style绑定

操作元素的class列表和内联样式是数据绑定的一个常见需求.因为它们都是属性,所以我们可以使用v-bind处理它们:只需要通过表达式计算出字符串结果即可.不过拼接字符串比较麻烦,因此在v-bind用于class和style时,vue做了专门的增强,表达式结果的类型除了字符串之外,还可以是对象和数组. 绑定HTML Class (1) 对象语法可以给v-bind:class一个对象,以动态切换class: <div v-bind:class="{active: isActive}"

Vue.js Class 与 Style 绑定

绑定 Class <!DOCTYPE html> <html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml"> <head> <meta charset="UTF-8"> <title>class</title> <style> span{ display:inline-block; } .static{

vue中,class与style绑定

<template> <div> <p v-bind:class="{active:isActive,'demo':Demo}">嘿嘿</p> <p v-bind:class="styleObj">哈哈</p> <p v-bind:class="styleObj2">咯吱咯吱</p> <p v-bind:class="[active1]

Vue.2.0.5-Class 与 Style 绑定

Class 与 Style 绑定 数据绑定一个常见需求是操作元素的 class 列表和它的内联样式.因为它们都是属性 ,我们可以用v-bind 处理它们:只需要计算出表达式最终的字符串.不过,字符串拼接麻烦又易错.因此,在 v-bind 用于 class 和 style 时, Vue.js 专门增强了它.表达式的结果类型除了字符串之外,还可以是对象或数组. 绑定 HTML Class 对象语法 我们可以传给 v-bind:class 一个对象,以动态地切换 class . <div v-bind

Vue#Class 与 Style 绑定

绑定HTMLCLASS 在我没看这之前,我觉得要写绑定class ,应该像绑定数据一样这么写 class ={{class-a}} 看官方教程时,不推荐这么写,推荐这样 v-bind:class="{ 'class-a': isA, 'class-b': isB }" 官方的解释,我觉得还是挺接地气的,最起码我能看的懂. 数据绑定一个常见需求是操作元素的 class 列表和它的内联样式.因为它们都是属性,我们可以用 v-bind 处理它们:我们只需要计算出表达式最终的字符串.不过,字符

Vue教程:Class 与 Style 绑定(四)

绑定 HTML Class 对象语法 ①.添加单个class: <div v-bind:class="{ active: isActive }"></div> 上面的语法表示 active 这个 class 存在与否将取决于数据属性 isActive为真还是假. ②.添加多个class: <div class="static" v-bind:class="{ active: isActive, 'text-danger': h

VUE:class与style强制绑定

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style> .aClass{ color:red; } .bClass{ color:blue; } .cClass{ font-size: 30px; } </style> </head> <body> <!-- 1.理

vue 绑定样式的几种方式

vue 绑定样式 对象语法 1.v-bind:class设置一个对象,动态切换class <div :class="{'active':isActive}">xxx</div> 样式是否起作用,根据isActive的布尔值是否为true 2.:class可以和class共存 <div class="static" :class="{'active':isActive,'error':isError}">xxx&