- 資訊首頁(yè) > 開(kāi)發(fā)技術(shù) > web開(kāi)發(fā) > JavaScript >
- Vue記事本實(shí)例詳解
本文實(shí)例為大家分享了Vue實(shí)現記事本功能的具體代碼,供大家參考,具體內容如下
實(shí)例功能點(diǎn)不多,主要難點(diǎn)在于筆記文本對象數組的添加,刪除,以及對組件的綁定同步事件。
核心代碼
<section id="todoapp"> <!-- 輸入框 --> <header class="header"> <h1>記事本</h1> <input v-model="note" autofocus="autofocus" autocomplete="off" placeholder="請輸入任務(wù)" class="new-todo" /> <div style="text-align: right;width: 90%;height: 3%;"> <button value="記錄" style="text-align: center" @click="addnote">記錄</button> </div> </header> <!-- 列表區域 --> <section class="main"> <ul class="todo-list"> <li class="todo" 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 class="clear-completed" @click="delnote"> Clear </button> </footer> </section> <script> let vue = new Vue({ el:"#todoapp", data:{ note:"好好學(xué)習,天天向上", index:0, notes:[ "寫(xiě)代碼", "吃飯飯", "睡覺(jué)覺(jué)" ] }, methods:{ addnote:function () { this.notes.push(this.note); }, delnote:function () { this.notes = []; } } }); </script>
關(guān)于vue.js組件的教程,請大家點(diǎn)擊專(zhuān)題進(jìn)行學(xué)習。
以上就是本文的全部?jì)热?,希望對大家的學(xué)習有所幫助,也希望大家多多支持腳本之家。
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自本網(wǎng)站內容采集于網(wǎng)絡(luò )互聯(lián)網(wǎng)轉載等其它媒體和分享為主,內容觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如侵犯了原作者的版權,請告知一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容,聯(lián)系我們QQ:712375056,同時(shí)歡迎投稿傳遞力量。
Copyright ? 2009-2022 56dr.com. All Rights Reserved. 特網(wǎng)科技 特網(wǎng)云 版權所有 特網(wǎng)科技 粵ICP備16109289號
域名注冊服務(wù)機構:阿里云計算有限公司(萬(wàn)網(wǎng)) 域名服務(wù)機構:煙臺帝思普網(wǎng)絡(luò )科技有限公司(DNSPod) CDN服務(wù):阿里云計算有限公司 百度云 中國互聯(lián)網(wǎng)舉報中心 增值電信業(yè)務(wù)經(jīng)營(yíng)許可證B2
建議您使用Chrome、Firefox、Edge、IE10及以上版本和360等主流瀏覽器瀏覽本網(wǎng)站