This article describes the v-bind attribute, class and style usage of vue basics. Share it for your reference, as follows:
1. Attributes
property:
v-bind:src=""
width/height/title....
Abbreviation:
:src="" recommend
<img src="{{url}}" alt="">
The effect can be produced, but there will be a 404 error<img v-bind:src="url" alt="">
The effect can be released, and no 404 request will be sent
=function(){ new Vue({ el:'#box', data:{ url:'/img/bd_logo1.png', w:'200px', t:'This is a beautiful picture' }, methods:{ } }); };
<div > <!--<img src="{{url}}" alt="">--> <img :src="url" alt="" :width="w" :title="t"> </div>
2. class and style
:class="" v-bind:class=""
:style="" v-bind:style=""
:class="[red]" red is data
:class="[red,b,c,d]"
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> <style> .red{ color: red; } .blue{ background: blue; } </style> <script src=""></script> <script> =function(){ new Vue({ el:'#box', data:{ claOne:'red',//The red here is the class class name claTwo:'blue' }, methods:{ } }); }; </script> </head> <body> <div > <!--HerecalOne,calTworefer todataData in--> <strong :class="[claOne,claTwo]">Word...</strong> </div> </body> </html>
:class="{red:true, blue:false}"//Here is { json}
<style> .red{ color: red; } .blue{ background: blue; } </style> <script src=""></script> <script> =function(){ new Vue({ el:'#box', data:{ }, methods:{ } }); }; </script> <div > <strong :class="{red:true,blue:true}">Word...</strong> </div>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> <style> .red{ color: red; } .blue{ background: blue; } </style> <script src=""></script> <script> =function(){ new Vue({ el:'#box', data:{ a:true, b:false }, methods:{ } }); }; </script> </head> <body> <div > <strong :class="{red:a,blue:b}">Word...</strong> </div> </body> </html>
data:{ json:{red:a, blue:false} }
:class="json"
Official recommended usage
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> <style> .red{ color: red; } .blue{ background: blue; } </style> <script src=""></script> <script> =function(){ new Vue({ el:'#box', data:{ json:{ red:true, blue:true } }, methods:{ } }); }; </script> </head> <body> <div > <strong :class="json">Word...</strong> </div> </body> </html>
style:
:style="[c]"
.red{ color: red; } <div > <strong :style="{color:'red'}">Word...</strong> </div>
:style="[c,d]"
Note: Compound style, using camel nomenclature
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> <style></style> <script src=""></script> <script> =function(){ new Vue({ el:'#box', data:{ c:{color:'red'},//The red here is class.red b:{backgroundColor:'blue'}//Note: Compound style, using camel nomenclature }, methods:{ } }); }; </script> </head> <body> <div > <strong :style="[c,b]">Word...</strong> </div> </body> </html>
:style="json"
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> <style></style> <script src=""></script> <script> =function(){ new Vue({ el:'#box', data:{ a:{ color:'red', backgroundColor:'gray' } }, methods:{ } }); }; </script> </head> <body> <div > <strong :style="a">Word...</strong> </div> </body> </html>
I hope this article will be helpful to everyone's programming.