vue 用mixin写一个删除事件

src/layout/mixin/delRow.js

 1 export default function(config) {
 2   const { url = '' } = config
 3   return {
 4     methods: {
 5     // 删除
 6       delRow(id) {
 7         this.$confirm('是否删除该信息?', '提示', {
 8           confirmButtonText: '确定',
 9           cancelButtonText: '取消',
10           type: 'warning'
11         }).then(() => {
12           url(id).then(res => {
13             if (res.code === 20000) {
14               this.$message({
15                 showClose: true,
16                 message: res.message,
17                 type: 'success'
18               })
19               this.queryListByPage()
20             }
21           })
22         }).catch(() => {
23           this.$message({
24             type: 'info',
25             message: '已取消删除'
26           })
27         })
28       }
29     }
30   }
31 }

<template v-slot="scope">
          <el-button
            type="text"
            @click="delRow(scope.row.lngparamid)"
          >删除</el-button>
        </template>
      </el-table-column>
 
 

<script>
z import DelRow from '@/layout/mixin/delRow'
2 const delRowMixin = new DelRow({ url: delData })
3 export default {
4   name: 'ExtendedFieldSettingTableArea',
5   mixins: [calculateCommonTableHeight, delRowMixin],
6 }
</script>
原文地址:https://www.cnblogs.com/hellofangfang/p/13590481.html