增加方法:1、用“:class="['类名']”语句添加;2、用“:class="['类名1','类名2',{属性名(类名):'属性值(true或false)}]"”语句;3、用“:class="{属性名(类名):true}”语句;4、用“:style="{'样式名':'样式值'}"”语句;5、用“:style="样式"”语句增加;6、用“:style="[data]"”语句。

本教程操作环境:windows7系统、vue3版,DELL G3电脑。
类名必须用引号 引起来;
1、数组
<h1>这种方法 需要用 v-bind: => : 绑定</h1>
2、数组中使用三元表达式
<h1>这种方法 需要用 v-bind: => : 绑定</h1>
3、数组中嵌套对象
<h1>这种方法 需要用 v-bind: => : 绑定</h1>
4、直接适用对象
<h1>这种方法 需要用 v-bind: => : 绑定</h1>
1、直接在元素上通过 :style 的形式
<h1>这种方法 需要用 v-bind: => : 绑定</h1>
2、将样式对象,定义到data 中,在引用到 :style 中
<h1>这种方法 需要用 v-bind: => : 绑定</h1>
3、在 :style 中通过数组,引用多个 data 上的样式对象;
<h1>这种方法 需要用 v-bind: => : 绑定</h1>
代码实例:
nbsp;html>
<meta>
<meta>
<meta>
<title>Vue样式的运用</title>
<style>
* {
margin: 0;
padding: 0;
}
.box {
width: 150px;
height: 150px;
background: skyblue;
line-height: 150px;
text-align: center;
}
.border {
border-radius: 50%;
}
.color {
color: #fff;
font-size: 24px;
}
</style>
<div>
<button>切换</button>
<!-- 添加样式/切换样式 -->
<!-- 对象方式 border 数据模型 tagger 真假 真显示 假隐藏-->
<!-- <div class="box" :class="{'border':tagger}">添加style样式</div> -->
<!-- 表达式 -->
<!-- <div :class="tagger ? 'border' : ''" class="box">添加style样式</div> -->
<!-- 数组 -->
<div>添加style样式</div>
</div>
<script></script>
<script>
let vm = new Vue({
el: '#app',
data: {
tagger : true,
vstyle : ['border','box'],
vObj : {"border":true,"color":true,"box":true}
},
methods: {
}
})
</script>(学习视频分享:、)
以上就是vue怎么在元素上增加样式的详细内容,更多请关注本站点其它相关文章!
本文地址:https://www.stayed.cn/item/26727
转载请注明出处。
本站部分内容来源于网络,如侵犯到您的权益,请 联系我