vue+element实现删除功能

vue+element实现删除功能



一、api文件夹中编写api接口

在这里插入图片描述

代码如下

export function delBannerList(params) {
	return request({
		url: '/banner/del',
		method: 'post',
		params
	})
}

二、编写删除按钮

在这里插入图片描述

代码如下(示例):

<el-table v-loading="listLoading" :data="bannerData" stripe style="width: 100%">
			<el-table-column prop="id" label="编号" width="130">
			</el-table-column>
			<el-table-column prop="bname" label="轮播图名字" width="180">
			</el-table-column>
			<el-table-column prop="burl" label="轮播图地址" width="180">
			</el-table-column>
			<el-table-column prop="weight" label="权重" width="130">
			</el-table-column>
			<el-table-column prop="" label="操作" fixed="right">
				<el-row slot-scope="scope">
					<el-button type="primary" icon="el-icon-edit" @click="updBtn(scope)" circle></el-button>
					<!-- 删除按钮 -->
					<el-button type="danger" icon="el-icon-delete" @click="delBanner(scope.$index, scope.row)" circle>
					</el-button>
				</el-row>
			</el-table-column>
		</el-table>

三、使用api文件夹中的接口

代码如下(示例):

	delBanner(index, row) {
				this.$confirm("是否确认删除本条数据,删除后不可恢复?", "提示", {
					confirmButtonText: "确定",
					cancelButtonText: "取消",
					type: "info"
				}).then(() => {
					delBannerList({
						id: row.id
					}).then(res => {
						if (res.code == 0) {
							this.$message({
								showClose: true, //可关闭的弹窗
								message: '删除成功',
								type: 'success',
								duration: '3000'
							});
							//刷新页面,也可不这样写
							setTimeout(function() {
								window.location.reload();
							}, 1000);
						} else {
							this.$message.error(res.msg);
						}
					})
				})


			}

该处使用的url网络请求的数据。

并且在methods:{}中编写。


总结

这几天学习了vue+element脚手架,实现基础的增删改需求。

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值