數(shù)據(jù)綁定
目前創(chuàng)新互聯(lián)已為數(shù)千家的企業(yè)提供了網(wǎng)站建設(shè)、域名、虛擬主機(jī)、網(wǎng)站改版維護(hù)、企業(yè)網(wǎng)站設(shè)計(jì)、鄂倫春網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長(zhǎng),共同發(fā)展。
1.單向綁定
<div id="app"> {{massage}} </div> var app = new Vue({ el:"#app", data:{ message:"Hello,vue.js!" }
2.雙向綁定
<div id="app"> <p>{{message}}</p> <input v-model="message" /> </div> var app = new Vue({ el:"#app", data:{ message:"Hello,vue.js!" }
3.v-for列表渲染
<div id="app"> <ul> <li v-for="todo in todos"> {{ todo.text }} </li> </ul> </div> new Vue({ el:"#app", data:{ todos:[ {text:"abcdef"}, {text:"123456"}, {text:"qwerta"} ] } })
3.處理用戶輸入
<div id="app"> <p>{{ message }}</p> <button v-on:click="reverseMessage">Reverse Message</button> </div> new Vue({ el: "#app", data:{ message:"Hello Vue.js!" }, methods:{ reverseMessage:function() { this .message = this.message.split('').revserse().join(''); } } })
4.綜合
<div id="app"> <input v-model="newTodo" v-on:keyup.enter="addTodo" /> <ul> <li v-for = "todo in todos"> <span>{{ todo.text }}</span> <button v-on:click="removeTodo($index)">X</button> </li> </ul> </div>
<script type="text/javascript" src="js/vue.min.js"></script> <script> new Vue({ el:"#app", data:{ newTodo:"", todos:[ { text:'Add some todos 1' }, { text:'Add some todos 2' },{ text:'Add some todos 3' } ] }, methods:{ addTodo: function(){ //去除首尾的空格 var text = this.newTodo.trim(); //去除后非空的話 if(text){ this.todos.push({ text: text }) this.newTodo = '' } }, removeTodo: function(index){ this.todos.splice( index, 1 ) } } }) </script>
以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時(shí)也希望多多支持創(chuàng)新互聯(lián)!
當(dāng)前標(biāo)題:Vue.js基礎(chǔ)知識(shí)小結(jié)
網(wǎng)站路徑:http://chinadenli.net/article18/pijedp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供手機(jī)網(wǎng)站建設(shè)、定制網(wǎng)站、電子商務(wù)、外貿(mào)建站、小程序開發(fā)、網(wǎng)站策劃
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
營(yíng)銷型網(wǎng)站建設(shè)知識(shí)