node-vue-mongodb全栈项目-创建后台管理界面-分类删除(六)

296 阅读1分钟

1.编写后台管理界面

admin->views->CategriesList.vue

 // 点击删除按钮
        deleteSub(row) {
            this.$confirm(`此操作将删除分类${row.cateName}, 是否继续?`, '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(async () => {
                // 发送删除请求
                const res =  await this.$_http.delete(`catergories/${row._id}`)
                this.fecth()
                this.$message({
                    type: 'success',
                    message: '删除成功!'
                });
                console.log(res);
            })
        }

2.编写服务端接口

serve->router->admin->index.js

 // 删除分类接口
    router.delete('/catergories/:id', async (req, res) => {
        const model = await Category.findByIdAndDelete(req.params.id)
        // 把model发送给客户端,让客户端知道传入数据库的是什么
        res.send({
            success: true
        })
        
    })