Vue demo:记事本

本文将介绍如何使用Vue.js构建一个简单的记事本应用。通过结合JavaScript和HTML,我们将实现添加、编辑和删除笔记的功能,展示Vue.js在动态数据绑定和组件化方面的优势。
摘要由CSDN通过智能技术生成

记事本:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<div align="center">
			<h2>欢迎使用xxx记事本</h2>
		</div>
		<div id="app" align="center">
			<input type="text" v-model="inputValue" value="请输入内容" />
			<input type="button" value="添加" @click="addNote"/>
			<table style="border: 1px solid darkgray;height: auto;width: 219px;">
				<tr v-for="(item,index) in noteList">
					<td>
						<span style="font-size: 2px;">{{ ++index }}{{ item }}</span>
						<span style="float: right;font-size: 2px;" @click="removeNote(index)"/>
							删除
						</span>
					</td>
				</tr>
			</table >
			<div style="font-size: 2px;">
				<span>内容数目:{{ noteList.length }}</span>
				<span style="margin-left: 100px;" @click="clearNote">
					清空
				</span>
			</div>
		</div>
		
		<!-- 导入开发版本的Vue -->
		<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
		
		<script>
			var app = new Vue({
				el:"#app",
				data:{
					noteList:[],
					inputValue:"请输入内容"
				},
				methods:{
					addNote:function(){
						this.noteList.push(this.inputValue);
						this.inputValue = "请输入内容";
					},
					removeNote:function(index){
						this.noteList.splice(index,1);
					},
					clearNote:function(){
						this.noteList.splice(0,this.noteList.length);
					}
				}
			})
		</script>
	</body>
</html>

结果:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值