詳解VUE中v-bind的基本用法
這兩天學(xué)習(xí)了v-bind的基本用法,所以,今天添加一點(diǎn)小筆記。
1. v-bind:class(根據(jù)需求進(jìn)行選擇)
1.1
<style>
.box{
background-color: #ff0;
}
.textColor{
color: #000;
}
.textSize{
font-size: 30px;
}
</style>
<div id="app">
<span class="box" :class="{'textColor':isColor, 'textSize':isSize}">我是字</span>
</div>
<script>
new Vue({
el: "#app",
data:{
isColor:true,
isSize:true
}
})
</script>
1.2
<style>
.box{
background-color: #ff0;
}
.textColor{
color: #000;
}
.textSize{
font-size: 30px;
}
</style>
<div id="app">
<span class="box" :class="classObject">我是字</span>
</div>
<script>
new Vue({
el: "#app",
data:{
classObject:{
'textColor': true,
'textSize': true
}
}
})
</script>
1.3
<style>
.box{
background-color: #ff0;
}
.textColor{
color: #0f0;
}
.textSize{
font-size: 30px;
}
</style>
<div id="app">
<span class="box" :class="[classA,classB]">我是字</span>
</div>
<script>
new Vue({
el: "#app",
data:{
classA: 'textColor',
classB: 'textSize'
}
})
</script>
1.4
<style>
.box{
background-color: #ff0;
}
.textColor{
color: #0f0;
}
.textSize{
font-size: 30px;
}
</style>
<div id="app">
<span class="box" :class="[isA?classA:'', classB]">我是字</span>
</div>
<script>
new Vue({
el: "#app",
data:{
classA: 'textColor',
classB: 'textSize',
isA: false
}
})
</script>
2.v-bind:style (根據(jù)需求進(jìn)行選擇,駝峰式)
2.1
<div id="app">
<span class="box" :style="{color:activeColor, fontSize:size,textShadow:shadow}">我是字</span>
</div>
<script>
new Vue({
el: "#app",
data:{
activeColor: 'red',
size: '30px',
shadow: '5px 2px 6px #000'
}
})
</script>
2.2
<div id="app">
<span class="box" :style="styleObject">我是字</span>
</div>
<script>
new Vue({
el: "#app",
data:{
styleObject:{
color: 'red',
fontSize: '30px',
textShadow: '5px 2px 6px #000'
}
}
})
</script>
2.3
<div id="app">
<span class="box" :style="[styleA,styleB]">我是字</span>
</div>
<script>
new Vue({
el: "#app",
data:{
styleA:{
fontSize: '30px',
color: 'red'
},
styleB:{
textShadow: '5px 2px 6px #000'
}
}
})
</script>
2.4
<div id="app">
<span class="box" :style="[isA?styleA:'', styleB]">我是字</span>
</div>
<script>
new Vue({
el: "#app",
data:{
styleA:{
fontSize: '30px',
color: 'red'
},
styleB:{
textShadow: '5px 2px 6px #000'
},
isA: false
}
})
</script>
3.v-bind:src
<div id="app">
<img :src="url" />
</div>
<script>
new Vue({
el: "#app",
data:{
url: "../img/pg.png"
}
})
</script>
4.v-bind:title
<div id="app">
<div :title="message">我是字</div>
</div>
<script type="text/javascript">
new Vue({
el: "#app",
data:{
message:"我是吱吱"
}
})
</script>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
vue 動(dòng)態(tài)設(shè)置瀏覽器標(biāo)題的方法詳解
這篇文章主要為大家介紹了vue動(dòng)態(tài)設(shè)置瀏覽器標(biāo)題的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助2021-12-12
動(dòng)態(tài)加載權(quán)限管理模塊中的Vue組件
本篇文章給大家詳細(xì)講解了如何在權(quán)限管理模塊中動(dòng)態(tài)的加載VUE組件的過程,有這方面需求的朋友跟著學(xué)習(xí)下吧。2018-01-01
vue實(shí)現(xiàn)頁面加載動(dòng)畫效果
這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)頁面加載動(dòng)畫效果,vue頁面出現(xiàn)正在加載的初始頁面與實(shí)現(xiàn)動(dòng)畫效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-09-09
使用vue cli4.x搭建vue項(xiàng)目的過程詳解
這篇文章主要介紹了使用vue cli4.x搭建vue項(xiàng)目的過程,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-05-05
詳解如何在Vue項(xiàng)目中發(fā)送jsonp請(qǐng)求
這篇文章主要介紹了詳解如何在Vue項(xiàng)目中發(fā)送jsonp請(qǐng)求,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-10-10
vue 實(shí)現(xiàn)復(fù)制內(nèi)容到粘貼板clipboard的方法
下面小編就為大家分享一篇vue 實(shí)現(xiàn)復(fù)制內(nèi)容到粘貼板clipboard的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-03-03
vue使用echarts實(shí)現(xiàn)立體柱形圖
這篇文章主要為大家詳細(xì)介紹了vue使用echarts實(shí)現(xiàn)立體柱形圖,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-04-04
移動(dòng)端Vue2.x Picker的全局調(diào)用實(shí)現(xiàn)
這篇文章主要介紹了移動(dòng)端Vue2.x Picker的全局調(diào)用實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-03-03

