本文已参与「新人创作礼」活动,一起开启掘金创作之路 接上一篇,回顾上一篇,已经写好了列表了,但还没有完善。例如,添加,删除等。
1. 先做删除功能,
(1)页面增加删除按钮
<el-tooltip v-permission="$store.jurisdiction.BannerDestroy" class="item" effect="dark" content="删除" placement="top-start">
<el-button :loading="formLoading" type="danger" icon="el-icon-delete" circle @click="handleDelete(scope.row)"/>
(2)js处理增加删除方法
handleDelete(row) { // 删除
const title = '是否确认删除该内容?'
const win = '删除成功'
this.t('hint.hint'), {
confirmButtonText: this.$t('usuel.confirm'),
cancelButtonText: this.$t('usuel.cancel'),
type: 'warning'
}).then(() => {
this.formLoading = true
destroy(row.id).then(() => {
this.getList()
this.dialogFormVisible = false
this.formLoading = false
this.$notify({
title: this.$t('hint.succeed'),
message: win,
type: 'success',
duration: 2000
})
}).catch(() => {
this.formLoading = false
})
}).catch(() => {
})
},
(3)api.js 增加删除的方法
export function destroy(id, data) {
data = Qs.parse(data)
return request({
url: 'question/destroy/' + id,
method: 'POST',
data
})
}
(4)后端增加删除的路由
Route::post('question/destroy/{id}', 'QuestionController@destroy')->middleware(['permissions:QannerDestroy']); //删除轮播
同时还要在后台的权限管理
(5)控制器增加删除方法
/**
* QuestionDestroy
* 问题轮播
* @param int $id
* @param Request $request
* @return \Illuminate\Http\Response
* @queryParam id int 问题ID
*/
public function destroy(request)
{
request, $id) {
if ($id) {
id);
Question::where('id', $Question->id)->delete();
}
return 1;
}, 5);
if ($return == 1) {
return resReturn(1, '删除成功');
} else {
return resReturn(0, return[1]);
}
}
这样删除功能就完成。 2. 接下来我们做添加功能
(1)先添加路由:
(2)添加权限
(3)增加添加方法
(4)后台的添加页在原来的list.vue上添加
index.vue的内容为:
<template > <div> <router-view /> </div> </template>
list添加的内容为
增加添加的方法
这样添加的功能基本就做完了,我们看下效果
总的来说,这个添加的功能还是比较简单的,当然这个方案也不是很好的,因为选项是固定的,不够灵活,后期可以优化为可随意增加选项的,这样就大方便了,因为时间的关系的,就先这样吧
总结:到这里,基本一个模块就做完了,可能写的过程中还有很多不好的地方,希望大家能指出来,在此,谢谢大家