Vue 记事本界面

文章展示了一个使用HbuilderX开发的基于Vue.js的本地应用,该应用具有创建、删除和清除列表项功能。HTML结构定义了页面布局,JavaScript处理数据绑定和方法,CSS用于样式设计,提供了添加、删除和清除按钮操作列表项。
摘要由CSDN通过智能技术生成

本地应用-记事本

1. 前端编译器 Hbuilder X

代码如下(示例):

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <script>
      var coverSupport = 'CSS' in window && typeof CSS.supports === 'function' && (CSS.supports('top: env(a)') ||
        CSS.supports('top: constant(a)'))
      document.write(
        '<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0' +
        (coverSupport ? ', viewport-fit=cover' : '') + '" />')
    </script>
    <title></title>
    <!--preload-links-->
    <!--app-context-->
	<script src="vue.js" type="text/javascript" charset="UTF-8"></script>	
  </head>
  
  //html
  <body>
	  <section id='todoapp' >
		  <header class='head'>
			<input style="position: relative;width: 90%;height: 25px;margin: 25px;" 
			autofocus='focus' autocomplete="off" placeholder="请输入内容" v-model="inputString">
		  </header>
		  <!-- 列表区域 -->
		  <section class='main' style='position: relative' >
			  <fieldset class='todo-li' >
				  <legend>计算机网络的发展历史</legend>
				  <li class='todo' style="list-style-type: none;" v-for="(item,index) in list">
					  <div class='view'> <!--div包裹了以下-->
						  <span class='index'>{{index+1}}.{{''}}</span>
						  <label>{{item}}</label>						  						  
					  </div>					  
				  </li>				  
			  </fieldset>
			  <button class='add-btn' v-on:click="added()">添加</button>
			  <button class='del-btn' @click="deleted(index)">删除</button>
			  <button class='complete-clr' @click="cleared()">清除</button>
		  </section>
		  <section class='foot' v-for="list.length!=0">
			总共<span class='todo-count'><strong>{{list.length}}</strong></span>	个列表项		
		  </section>
	  </section>
	
	//js  
	<script>		
		var app=new Vue({
			el:'#todoapp',
			data:{
				list:['第一代计算机主机面向无终端的网络',
				'第二代以通信子网和资源子网为中心',
				'第三代以Internet为中心的新一代网络'],
				inputString:''
			},
			methods:{
				added:function(){
					// this.list+=this.inputString 数组怎么增加元素
					this.list.push(this.inputString)
				},
				deleted:function(index){
					this.list.splice(index,1)
				},
				cleared:function(){
					this.list=[]
				},
			}			
		})		
	</script>
	
	//css
	<style>
		#todoapp{
			width: 80%;
			min-height: 250px;
			border: 1px solid black;
			font-family: 'Lucida Console', monospace;
			font-size: 14px;
			line-height: 1.5;
			padding: 5px;
			border: 2px solid #ccc;
			border-radius: 5px;
			box-shadow: 0 0 5px #ccc;
			background-color: #f1f1f1;
			color: #000;
		}		
		.todo-li{
			background-color: lightblue;
			color: black;
			border: 2px solid black;
			border-radius: 10px;
			padding: 10px 20px;
			font-size: 16px;
			text-align: left;
			/* list-style-image: url(./static/logo.png); */
		}
		.add-btn,.del-btn,.complete-clr{
			  background-color: red;
			  color: white;
			  border: 2px solid black;
			  border-radius: 10px;
			  padding: 5px 10px;
			  margin: 10px;
			  font-size: 16px;
			}
		.add-btn{
			  position:absolute;
			  right: 140px;
			}
		.del-btn{
			 position:absolute;
			  right: 70px;
			}
		.complete-clr{
			background-color: rosybrown;
			position:absolute;
			right: 0px;
			}
		}		
	</style>
		
  </body>
</html>

2.初始界面预览

在这里插入图片描述

3.添加 删除 清除

在这里插入图片描述

小黑记事本是一个使用Vue框架编写的项目,实现了简易的记事本功能。下面是部分小黑记事本Vue源代码: 模板部分: ```html <template> <div class="notebook"> <h1>小黑记事本</h1> <div class="input-container"> <textarea v-model="content" placeholder="开始编写"></textarea> </div> <div class="button-container"> <button @click="saveNote">保存</button> <button @click="clearNote">清空</button> </div> <div class="notes-container"> <h2>已保存的笔记</h2> <ul> <li v-for="(note, index) in notes" :key="index">{{ note }}</li> </ul> </div> </div> </template> ``` 脚本部分: ```javascript <script> export default { data() { return { content: '', notes: [], }; }, methods: { saveNote() { if (this.content.trim() !== '') { this.notes.push(this.content.trim()); this.content = ''; } }, clearNote() { this.content = ''; }, }, }; </script> ``` 样式部分: ```css <style scoped> .notebook { text-align: center; margin: 20px auto; } .input-container { margin-bottom: 20px; } textarea { width: 300px; height: 150px; } .button-container button { margin: 0 10px; } .notes-container { margin-top: 30px; } ul { list-style-type: none; padding-left: 0; } li { margin-top: 10px; } </style> ``` 以上是小黑记事本的一个简化版本,实现了输入内容的保存和清空,并将已保存的笔记展示在界面上。用户可以在文本框中输入内容,点击保存按钮即可将内容添加到已保存的笔记列表中。点击清空按钮可以清空文本框中的内容。小黑记事本提供了简单的界面交互,方便用户保存和管理笔记。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值