基于vue框架怎么实现一个简单的记事本
Admin 2022-07-08 群英技术资讯 779 次浏览
这篇文章给大家分享的是基于vue框架怎么实现一个简单的记事本。小编觉得挺实用的,因此分享给大家做个参考,文中的介绍得很详细,而要易于理解和学习,有需要的朋友可以参考,接下来就跟随小编一起了解看看吧。本文实例为大家分享了vue实现记事本小功能的具体代码,供大家参考,具体内容如下
直接上代码:
<!DOCTYPE html>
<html lang="en">
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<head>
<style>
#app {
margin: 0px auto;
width: 500px;
border: 1px solid gainsboro;
height: auto;
}
.title {
line-height: 50px;
text-align: center;
height: 50px;
font-weight: 20;
font-size: 36px;
background: #42b983;
border-bottom: 1px solid black;
}
input:focus {
border-color: #66afe9;
outline: 0;
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 8px rgba(102, 175, 233, .6);
box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 8px rgba(102, 175, 233, .6)
}
.file-container{
overflow: hidden;
margin-top: 10px;
}
.openfile-btn{
float: left;
margin-left: 10px;
}
#file_path{
margin-left: 10px;
width: 300px;
}
#file_con{
display: block;
border:0;
border-radius:5px;
background-color:rgba(241,241,241,.98);
width: 480px;
height: 250px;
margin-top: 10px;
margin-left: 10px;
resize: none;
}
ul,
li {
padding: 0;
margin: 0;
list-style: none;
}
.li-div {
text-align: center;
overflow: hidden;
margin-top: 5px;
/*border: 3px solid blanchedalmond;*/
}
.bot{
height: 30px;
}
.show-details{
float: right;
margin-right: 10px;
}
.show-btn{
/*display: block;*/
float: right;
margin-right: 10px;
}
</style>
</head>
<body>
<div id="app">
<div class="title">
记事本
</div>
<div>
<div class="file-container">
<input class="openfile-btn" type="button" value="从本地导入" id="fileImport" v-on:click="clickLoad">
<input type="file" id="files" ref="refFile" style="display: none" v-on:change="fileLoad">
<input type="text" v-model="path" id="file_path" disabled="disabled">
<input type="button" value="确定导入" style="float:right; margin-right: 10px " v-on:click="addfile"></button>
<textarea type="text" id="file_con" autoHeight="true" v-model="input_file"></textarea>
</div>
</div>
<hr>
<div class="content">
<ul>
<li v-for="(item, index) in message">
<div class="li-div">
<span>{{++index}}</span>
<label>{{item}}</label>
<button @click="remove(index)" class="show-btn">删除</button>
<button @click="show(index)" class="show-btn" v-if="item.length>30">详情</button>
</div>
</li>
</ul>
</div>
<hr>
<div v-show="message.length>0" class="bot">
<div style="float: left; margin-left: 10px">
当前记事本记录数:{{message.length}}
</div>
<div class="del-btn">
<button @click="clear"class="show-btn">清空</button>
</div>
</div>
</div>
<script>
let app = new Vue({
el: '#app',
data: {
//tmp: "",
message: [],
path:'',
input_file:'',
sub_inpufile:'',
tmp_file:''
},
methods: {
clickLoad: function (){
this.$refs.refFile.dispatchEvent(new MouseEvent('click'))
},
fileLoad() {
const selectedFile = this.$refs.refFile.files[0];
var name = selectedFile.name; //选中文件的文件名
var size = selectedFile.size; //选中文件的大小
var reader = new FileReader();
reader.readAsText(selectedFile);
this.path = name;
console.log("文件名:" + name + "大小:" + size);
reader.onload = function() {
let file_s = this.result;
document.getElementById('file_con').value=file_s;
}
},
addfile:function (){
var file = document.getElementById('file_con').value;
this.input_file=file;
this.tmp_file=file; //用来存储原文件
//console.log("this.input_file:"+this.input_file)
if (file == null || file == "") {
alert("输入不能为空");
} else {
if(file.length>30)
{
this.sub_inpufile=file.substring(0,30)+'...'
this.message.push(this.sub_inpufile);
this.input_file=''
this.path=''
console.log(this.sub_inpufile)
}
else{
this.message.push(this.input_file);
this.input_file=''
this.path=''
}
}
},
remove: function (index) {
var flag = confirm("是否要删除删除" + index);
if (flag == true) {
this.message.splice(index-1, 1);
}
},
show:function (){
alert(this.tmp_file) //有字数限制,可自定义组件
},
clear: function () {
this.message = [];
},
},
})
</script>
</body>
</html>
效果:

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
JS获取扩展名的方法有多少种,代码是什么,有不少朋友对此感兴趣,下面小编给大家整理和分享了相关知识和资料,易于大家学习和理解,有需要的朋友可以借鉴参考,下面我们一起来了解一下吧。
vuex辅助函数的用法是什么?vue中辅助函数有mapState、mapActions、mapMutations等等,对新手来说可能不是很了解vuex辅助函数的使用,因此这篇文章就给大家来介绍一下vuex辅助函数。
微信小程序自定义导航的方法 本文实例为大家分享了微信小程序自定义导航的具体代码,供大家参考,具体内容如下 在app.js中获取状态栏信息和胶囊按钮信息 onLaunch() { // 展示本地存储能力 const logs = wx.getStorageSync('logs') || [] logs.unshift(Date.now()) wx.setStorageSync('logs', logs) // 获取系统信息 this.globalData.systemInfo
这篇文章给大家分享的是jQuery中实现增加tr行的方法。小编觉得挺实用的,因此分享给大家做个参考,文中的示例代码介绍得很详细,有需要的朋友可以参考,接下来就跟随小编一起了解看看吧。
vue+elementUI配置表格的列显示与隐藏,供大家参考,具体内容如下描述:表格的列过多时,可以根据需要控制列的显示与隐藏,目前是采用Vue+elementUI(适配Vue3的Element Plus)实现的,具体效果与代码如下:效果图:完整代码:template div id=app el-table :
成为群英会员,开启智能安全云计算之旅
立即注册关注或联系群英网络
7x24小时售前:400-678-4567
7x24小时售后:0668-2555666
24小时QQ客服
群英微信公众号
CNNIC域名投诉举报处理平台
服务电话:010-58813000
服务邮箱:service@cnnic.cn
投诉与建议:0668-2555555
Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008