這篇文章主要講解了“Vue實現記事本功能實例”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“Vue實現記事本功能實例”吧!
本文實例為大家分享了Vue實現記事本功能的具體代碼,供大家參考,具體內容如下



實例功能點不多,主要難點在于筆記文本對象數組的添加,刪除,以及對組件的綁定同步事件。
核心代碼
<section id="todoapp">
<!-- 輸入框 -->
<header class="header">
<h2>記事本</h2>
<input
v-model="note"
autofocus="autofocus"
autocomplete="off"
placeholder="請輸入任務"
class="new-todo"
/>
<div >
<button value="記錄" @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:"好好學習,天天向上",
index:0,
notes:[
"寫代碼",
"吃飯飯",
"睡覺覺"
]
},
methods:{
addnote:function () {
this.notes.push(this.note);
},
delnote:function () {
this.notes = [];
}
}
});
</script>感謝各位的閱讀,以上就是“Vue實現記事本功能實例”的內容了,經過本文的學習后,相信大家對Vue實現記事本功能實例這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。