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='請(qǐng)輸入任務(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組件的教程,請(qǐng)大家點(diǎn)擊專題vue.js組件學(xué)習(xí)教程進(jìn)行學(xué)習(xí)。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. CSS hack用法案例詳解2. 利用promise及參數(shù)解構(gòu)封裝ajax請(qǐng)求的方法3. JSP數(shù)據(jù)交互實(shí)現(xiàn)過程解析4. asp(vbs)Rs.Open和Conn.Execute的詳解和區(qū)別及&H0001的說明5. ASP 信息提示函數(shù)并作返回或者轉(zhuǎn)向6. Ajax實(shí)現(xiàn)表格中信息不刷新頁面進(jìn)行更新數(shù)據(jù)7. PHP設(shè)計(jì)模式中工廠模式深入詳解8. 解決AJAX返回狀態(tài)200沒有調(diào)用success的問題9. .NET中l(wèi)ambda表達(dá)式合并問題及解決方法10. ThinkPHP5實(shí)現(xiàn)JWT Token認(rèn)證的過程(親測(cè)可用)
