Vue記事本實例詳解
本文實例為大家分享了Vue實現記事本功能的具體代碼,供大家參考,具體內容如下
實例功能點不多,主要難點在于筆記文本對象數組的添加,刪除,以及對組件的綁定同步事件。
核心代碼
<section id='todoapp'> <!-- 輸入框 --> <header class='header'><h1>記事本</h1><inputv-model='note' autofocus='autofocus' autocomplete='off' placeholder='請輸入任務' /><div style='text-align: right;width: 90%;height: 3%;'> <button value='記錄' @click='addnote'>記錄</button></div> </header> <!-- 列表區域 --> <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> <!-- 統計和清空 --> <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:'好好學習,天天向上', index:0, notes:[ '寫代碼', '吃飯飯', '睡覺覺' ]},methods:{ addnote:function () { this.notes.push(this.note); }, delnote:function () { this.notes = []; }} });</script>
關于vue.js組件的教程,請大家點擊專題vue.js組件學習教程進行學習。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。
相關文章: