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. 利用promise及參數(shù)解構(gòu)封裝ajax請(qǐng)求的方法2. Nginx+php配置文件及原理解析3. windows服務(wù)器使用IIS時(shí)thinkphp搜索中文無效問題4. .NET中l(wèi)ambda表達(dá)式合并問題及解決方法5. JSP數(shù)據(jù)交互實(shí)現(xiàn)過程解析6. 淺談python出錯(cuò)時(shí)traceback的解讀7. python matplotlib:plt.scatter() 大小和顏色參數(shù)詳解8. Ajax實(shí)現(xiàn)表格中信息不刷新頁面進(jìn)行更新數(shù)據(jù)9. Python importlib動(dòng)態(tài)導(dǎo)入模塊實(shí)現(xiàn)代碼10. ASP 信息提示函數(shù)并作返回或者轉(zhuǎn)向
