您好,登錄后才能下訂單哦!
這篇文章主要為大家展示了“vue快捷鍵與基礎(chǔ)指令的示例分析”,內(nèi)容簡(jiǎn)而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“vue快捷鍵與基礎(chǔ)指令的示例分析”這篇文章吧。
v-bind可以簡(jiǎn)寫成 :
<img src="{{url}}">→<img :src="url" :width="50px"> v-on:click可以寫成@click <button @click="up()"></button>
v-if實(shí)例 可以通過對(duì)對(duì)象操作條件來實(shí)現(xiàn)想要展示的效果
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script type="text/javascript" src="js/vue.min.js"></script> </head> <body> <div id="app"> <p v-if="seen">現(xiàn)在你看到我了</p> <template v-if="ok"> <h2>天氣炎熱</h2> </template> </div> <script> new Vue({ el: "#app", data: { seen:false, ok: true } }) </script> </body> </html>
v-for實(shí)例:v-for是可以做循環(huán)數(shù)組使用的
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script type="text/javascript" src="js/vue.min.js"></script> </head> <body> <div id="app"> <ol> <li v-for="x in lists">{{x.title}}</li> </ol> </div> <script> new Vue({ el: "#app", data: { lists: [ { id: 1, title: "臧三" }, { id: 2, title: '李四' }, { id: 3, title: "王五" }, ] } }) </script> </body> </html>
v-show實(shí)例:v-show可以操作true/false來實(shí)現(xiàn)效果
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script type="text/javascript" src="js/vue.min.js"></script> </head> <body> <div id="app"> <input type="button" value="點(diǎn)擊" v-on:click="a=false" /> <div v-show="a"> </div> </div> <script> new Vue({ el: "#app", data: { a: true } }) </script> </body> </html>
:class實(shí)例:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script type="text/javascript" src="js/vue.js" ></script> <style> .red{ color:red } .blue{ background: blue; } </style> </head> <body> <div id="app"> <p :class="{red:a,blue:b}">我是123</p> </div> <script> new Vue({ el:"#app", data:{ a:true, b:true } }) </script> </body> </html>
第二種方法
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script type="text/javascript" src="js/vue.js" ></script> <style> .red{ color:red } .blue{ background: blue; } </style> </head> <body> <div id="app"> <p :class="json">我是123</p> </div> <script> new Vue({ el:"#app", data:{ json:{ red:true, blue:true } } }) </script> </body> </html>
以上是“vue快捷鍵與基礎(chǔ)指令的示例分析”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。