本文實例講述了vue data存儲數據及v-for循環用法。分享給大家供大家參考,具體如下:
vue data里面存儲數據
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>www.49028c.com vue data里面存儲數據</title> <style> </style> <script src="https://cdn.bootcss.com/vue/2.4.4/vue.min.js"></script> <script> window.onload=function(){ new Vue({ el:'body', data:{ msg:'welcome vue', msg2:12, msg3:true, arr:['apple','banana','orange','pear'], json:{a:'apple',b:'banana',c:'orange'} } }); }; </script></head><body> <input type="text" v-model="msg"> <input type="text" v-model="msg"> <br> {{msg}} <br> {{msg2}} <br> {{msg3}} <br> {{arr}} <br> {{json}}</body></html>
vue v-for循環
v-for循環:
v-for="name in arr"
{{value}} {{$index}}
v-for="name in json"
{{value}} {{index}} {{index}} {{key}}
v-for="(k,v) in json"
{{k}} {{v}} {{index}} {{index}} {{key}}
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>www.49028c.com vue v-for循環</title> <style> </style> <script src="https://cdn.bootcss.com/vue/2.4.4/vue.min.js"></script> <script> window.onload=function(){ new Vue({ el:'#box', data:{ arr:['apple','banana','orange','pear'], json:{a:'apple',b:'banana',c:'orange'} } }); }; </script></head><body> <div id="box"> <ul> <li v-for="value in arr"> {{value}} {{$index}} </li> </ul> <hr> <ul> <li v-for="value in json"> {{value}} {{$index}} {{$key}} </li> </ul> <hr> <ul> <li v-for="(k,v) in json"> {{k}} {{v}} {{$index}} {{$key}} </li> </ul> </div></body></html>
感興趣的朋友可以使用在線HTML/CSS/JavaScript代碼運行工具:http://tools.VeVB.COm/code/HtmlJsRun測試上述代碼運行效果。
希望本文所述對大家vue.js程序設計有所幫助。
新聞熱點
疑難解答