本文实例为大家分享了Vue实现记事本功能的具体代码,供大家参考,具体内容如下



实例功能点不多,主要难点在于笔记文本对象数组的添加,删除,以及对组件的绑定同步事件。
核心代码
<section id="todoapp">
<!-- 输入框 -->
<header class="header">
<h1>记事本</h1>
<input
v-model="note"
autofocus="autofocus"
autocomplete="off"
placeholder="请输入任务"
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:"好好学习,天天向上",
index:0,
notes:[
"写代码",
"吃饭饭",
"睡觉觉"
]
},
methods:{
addnote:function () {
this.notes.push(this.note);
},
delnote:function () {
this.notes = [];
}
}
});
</script>免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
长按识别二维码并关注微信
更方便到期提醒、手机管理