<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<script type="text/javascript" src="js/vue.min.js"></script>
<title>form</title>
<style type="text/css">
#table table {
width: 100%;
font-size: 14px;
border: 1px solid #eee
}
#table {
padding: 0 10px;
}
table thead th {
background: #f5f5f5;
padding: 10px;
text-align: left;
}
table tbody td {
padding: 10px;
text-align: left;
border-bottom: 1px solid #eee;
border-right: 1px solid #eee;
}
table tbody td span {
margin: 0 10px;
cursor: pointer;
}
.delete {
color: red;
}
.edit {
color: #008cd5;
}
.add {
border: 1px solid #eee;
margin: 10px 0;
padding: 15px;
}
input {
border: 1px solid #ccc;
padding: 5px;
border-radius: 3px;
margin-right: 15px;
}
button {
background: #008cd5;
border: 0;
padding: 4px 15px;
border-radius: 3px;
color: #fff;
}
#mask {
background: rgba(0, 0, 0, .5);
width: 100%;
height: 100%;
position: fixed;
z-index: 4;
top: 0;
left: 0;
}
.mask {
width: 300px;
height: 250px;
background: rgba(255, 255, 255, 1);
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
margin: auto;
z-index: 47;
border-radius: 5px;
}
.title {
padding: 10px;
border-bottom: 1px solid #eee;
}
.title span {
float: right;
cursor: pointer;
}
.content {
padding: 10px;
}
.content input {
width: 270px;
margin-bottom: 15px;
}
</style>
</head>
<body>
<div id="table">
<div class="add">
<input type="text" v-model="addDetail.title" name="title" value="" placeholder="标题" />
<input type="text" v-model="addDetail.user" name="user" value="" placeholder="发布人" />
<input type="date" v-model="addDetail.dates" name="date" value="" placeholder="发布时间" />
<button @click="adddetail">新增</button>
</div>
<table cellpadding="0" cellspacing="0">
<thead>
<tr>
<th>序号</th>
<th>标题</th>
<th>发布人</th>
<th>发布时间</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr v-for="(item,index) in newsList">
<td width="5%">{{index+1}}</td>
<td>{{item.title}}</td>
<td width="10%">{{item.user}}</td>
<td width="15%">{{item.dates}}</td>
<td width="10%"><span @click="deletelist(item.id,index)" class="delete">删除</span><span class="edit" @click="edit(item)">编辑</span></td>
</tr>
</tbody>
</table>
<div id="mask" v-if="editlist">
<div class="mask">
<div class="title">
编辑
<span @click="editlist=false">
X
</span>
</div>
<div class="content">
<input type="text" v-model="editDetail.title" name="title" value="" placeholder="标题" />
<input type="text" v-model="editDetail.user" name="user" value="" placeholder="发布人" />
<input type="date" v-model="editDetail.dates" name="date" value="" placeholder="发布时间" />
<button @click="update">更新</button>
<button @click="editlist=false">取消</button>
</div>
</div>
</div>
</div>
<script>
var app = new Vue({
el: '#table',
data: {
addDetail: {},
editlist: false,
editDetail: {},
newsList: [{
title: '在移动设备开发',
user: '张若昀',
dates: '2018-02-09',
id: "45211546"
}, {
title: '图形及特效特性',
user: '张若昀',
dates: '2018-02-09',
id: "61341341"
}, {
title: '设备兼容特性',
user: '张若昀',
dates: '2018-02-09',
id: "62451431"
}, {
title: 'W3C将致力于开发用于实时通信',
user: '张若昀',
dates: '2018-02-09',
id: "62345213"
}, {
title: '全新的表单输入对象',
user: '张若昀',
dates: '2018-02-09',
id: "23322445"
}],
editid:''
},
mounted() {
},
methods: {
//新增
adddetail() {
//这里的思路应该是把this.addDetail传给服务端,然后加载列表this.newsList
//this.newsList.push(this.addDetail)
this.newsList.push({
title: this.addDetail.title,
user: this.addDetail.user,
dates: this.addDetail.dates,
})
//axios.post('url',this.addDetail).then((res) =>{
//若返回正确结果,清空新增输入框的数据
//this.addDetail.title = ""
//this.addDetail.user = ""
//this.addDetail.dates = ""
//})
},
//删除
deletelist(id, i) {
this.newsList.splice(i, 1);
//这边可以传id给服务端进行删除 ID = id
//axios.get('url',{ID:id}).then((res) =>{
// 加载列表
//})
},
//编辑
edit(item) {
this.editDetail = {
title: item.title,
user: item.user,
dates: item.dates,
id: item.id
}
this.editlist = true
this.editid = item.id
},
//确认更新
update() {
//编辑的话,也是传id去服务端
//axios.get('url',{ID:id}).then((res) =>{
// 加载列表
//})
let _this= this
for(let i = 0; i < _this.newsList.length; i++) {
if(_this.newsList[i].id ==this.editid) {
_this.newsList[i] = {
title: _this.editDetail.title,
user: _this.editDetail.user,
dates: _this.editDetail.dates,
id: this.editid
}
this.editlist = false
}
}
}
}
})
</script>
</body>
</html>
vue表格增删改查
需积分: 50 57 浏览量
2019-03-04
09:10:52
上传
评论 9
收藏 34KB ZIP 举报
库行天下
- 粉丝: 19
- 资源: 10
最新资源
- 直接插入排序,冒泡排序,直接选择排序.zip
- 在排序2的基础上,再次对快排进行优化,其次增加快排非递归,归并排序,归并排序非递归版.zip
- 实现了7种排序算法.三种复杂度排序.三种nlogn复杂度排序(堆排序,归并排序,快速排序)一种线性复杂度的排序.zip
- 冒泡排序 直接选择排序 直接插入排序 随机快速排序 归并排序 堆排序.zip
- 课设-内部排序算法比较 包括冒泡排序、直接插入排序、简单选择排序、快速排序、希尔排序、归并排序和堆排序.zip
- Python排序算法.zip
- C语言实现直接插入排序、希尔排序、选择排序、冒泡排序、堆排序、快速排序、归并排序、计数排序,并带图详解.zip
- 常用工具集参考用于图像等数据处理
- 音乐展示网页、基于Stenography的图像数字水印添加与提取,以及基于颜色矩和Tamura算法的图像相似度评估算法py源码
- 基于EmguCV(OpenCV .net封装),图像数字水印加解密算法的实现,其中包含最低有效位算法,离散傅里叶变换算法+文档书
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈