Vue記事本實(shí)例詳解
本文實(shí)例為大家分享了Vue實(shí)現(xiàn)記事本功能的具體代碼,供大家參考,具體內(nèi)容如下
實(shí)例功能點(diǎn)不多,主要難點(diǎn)在于筆記文本對(duì)象數(shù)組的添加,刪除,以及對(duì)組件的綁定同步事件。
核心代碼
<section id='todoapp'> <!-- 輸入框 --> <header class='header'><h1>記事本</h1><inputv-model='note' autofocus='autofocus' autocomplete='off' placeholder='請輸入任務(wù)' /><div style='text-align: right;width: 90%;height: 3%;'> <button value='記錄' @click='addnote'>記錄</button></div> </header> <!-- 列表區(qū)域 --> <section class='main'><ul class='todo-list'> <li v-for='(n,index) in notes'> <div class='view'> <span class='index'>{{index+1}}</span> <label>{{n}}</label> <button class='destroy'></button> </div> </li></ul> </section> <!-- 統(tǒng)計(jì)和清空 --> <footer class='footer'><span class='todo-count'><strong>{{notes.length}}</strong> items left </span><button @click='delnote'> Clear</button> </footer> </section> <script> let vue = new Vue({el:'#todoapp',data:{ note:'好好學(xué)習(xí),天天向上', index:0, notes:[ '寫代碼', '吃飯飯', '睡覺覺' ]},methods:{ addnote:function () { this.notes.push(this.note); }, delnote:function () { this.notes = []; }} });</script>
關(guān)于vue.js組件的教程,請大家點(diǎn)擊專題vue.js組件學(xué)習(xí)教程進(jìn)行學(xué)習(xí)。
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
