element商品分類

B.創(chuàng)建子級(jí)路由

創(chuàng)建categories子級(jí)路由組件并設(shè)置路由規(guī)則

import Cate from './components/goods/Cate.vue'

path: '/home', component: Home, redirect: '/welcome', children: [
    { path: "/welcome", component: Welcome },
    { path: "/users", component: Users },
    { path: "/rights", component: Rights },
    { path: "/roles", component: Roles  },
    { path: "/categories", component: Cate  }
]

C.添加組件基本布局

在Cate.vue組件中添加面包屑導(dǎo)航以及卡片視圖中的添加分類按鈕

<template>
    <div>
        <h3>商品分類</h3>
        <!-- 面包屑導(dǎo)航 -->
        <el-breadcrumb separator="/">
            <el-breadcrumb-item :to="{ path: '/home' }">首頁(yè)</el-breadcrumb-item>
            <el-breadcrumb-item>商品管理</el-breadcrumb-item>
            <el-breadcrumb-item>商品分類</el-breadcrumb-item>
        </el-breadcrumb>
        <!-- 卡片視圖區(qū)域 -->
        <el-card>
            <!-- 添加分類按鈕區(qū)域 -->
            <el-row>
                <el-col>
                    <el-button type="primary">添加分類</el-button>
                </el-col>
            </el-row>
            <!-- 分類表格  -->

            <!-- 分頁(yè) -->
        </el-card>
    </div>
</template>

D.請(qǐng)求分類數(shù)據(jù)

請(qǐng)求分類數(shù)據(jù)并將數(shù)據(jù)保存在data中

<script>
export default {
  data() {
    return {
      // 商品分類數(shù)據(jù)列表
      cateList: [],
      //查詢分類數(shù)據(jù)的條件
      queryInfo: {
        type: 3,
        pagenum: 1,
        pagesize: 5
      },
      //保存總數(shù)據(jù)條數(shù)
      total: 0
    }
  },
  created() {
    this.getCateList()
  },
  methods: {
    async getCateList() {
      //獲取商品分類數(shù)據(jù)
      const { data: res } = await this.$http.get('categories', {
        params: queryInfo
      })

      if (res.meta.status !== 200) {
        return this.$message.error('獲取商品列表數(shù)據(jù)失敗')
      }
      //將數(shù)據(jù)列表賦值給cateList
      this.cateList = res.data.result
      //保存總數(shù)據(jù)條數(shù)
      this.total = res.data.total
      //   console.log(res.data);
    }
  }
}
</script>

E.使用插件展示數(shù)據(jù)

使用第三方插件vue-table-with-tree-grid展示分類數(shù)據(jù)
1).在vue 控制臺(tái)中點(diǎn)擊依賴->安裝依賴->運(yùn)行依賴->輸入vue-table-with-tree-gird->點(diǎn)擊安裝
2).打開(kāi)main.js封恰,導(dǎo)入vue-table-with-tree-grid
import TreeTable from 'vue-table-with-tree-grid'
.....
Vue.config.productionTip = false

//全局注冊(cè)組件
Vue.component('tree-table', TreeTable)
3).使用組件展示分類數(shù)據(jù)
<!-- 分類表格
:data(設(shè)置數(shù)據(jù)源) :columns(設(shè)置表格中列配置信息) :selection-type(是否有復(fù)選框)
:expand-type(是否展開(kāi)數(shù)據(jù)) show-index(是否設(shè)置索引列) index-text(設(shè)置索引列頭)
border(是否添加縱向邊框) :show-row-hover(是否鼠標(biāo)懸停高亮) -->
<tree-table :data="cateList" :columns="columns" :selection-type="false"
:expand-type="false" show-index index-text="#" border :show-row-hover="false">

</tree-table>

在數(shù)據(jù)中添加columns:
columns: [
    {label:'分類名稱',prop:'cat_name'}
]

F.自定義數(shù)據(jù)列

使用vue-table-with-tree-grid定義模板列并添加自定義列

//先在columns中添加一個(gè)列
columns: [
    {label:'分類名稱',prop:'cat_name'},
    //type:'template'(將該列設(shè)置為模板列)廓推,template:'isok'(設(shè)置該列模板的名稱為isok)
    {label:'是否有效',prop:'',type:'template',template:'isok'},
    {label:'排序',prop:'',type:'template',template:'order'},
    {label:'操作',prop:'',type:'template',template:'opt'}
]

<!-- 是否有效區(qū)域, 設(shè)置對(duì)應(yīng)的模板列: slot="isok"(與columns中設(shè)置的template一致) -->
<template slot="isok" slot-scope="scope">
  <i class="el-icon-success" v-if="scope.row.cat_deleted === false" style="color:lightgreen"></i>
  <i class="el-icon-error" v-else style="color:red"></i>
</template>
<!-- 排序 -->
<template slot="order" slot-scope="scope">
  <el-tag size="mini" v-if="scope.row.cat_level===0">一級(jí)</el-tag>
  <el-tag size="mini" type="success" v-else-if="scope.row.cat_level===1">二級(jí)</el-tag>
  <el-tag size="mini" type="warning" v-else>三級(jí)</el-tag>
</template>

<!-- 操作 -->
<template slot="opt" slot-scope="scope">
  <el-button size="mini" type="primary" icon="el-icon-edit">編輯</el-button>
  <el-button size="mini" type="danger" icon="el-icon-delete">刪除</el-button> 
</template>

G.完成分頁(yè)功能

<!-- 分頁(yè) -->
<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="queryInfo.pagenum" :page-sizes="[3, 5, 10, 15]" :page-size="queryInfo.pagesize" layout="total, sizes, prev, pager, next, jumper" :total="total">
</el-pagination>

//添加對(duì)應(yīng)的事件函數(shù)
methods:{
  .......
  handleSizeChange(newSize){
    //當(dāng)pagesize發(fā)生改變時(shí)觸發(fā)
    this.queryInfo.pagesize = newSize;
    this.getCateList();
  },
  handleCurrentChange(newPage){
    //當(dāng)pagenum發(fā)生改變時(shí)觸發(fā)
    this.queryInfo.pagenum = newPage;
    this.getCateList();
  }
}

H.完成添加分類

......
<!-- 添加分類按鈕區(qū)域 -->
<el-row>
  <el-col>
    <el-button type="primary" @click="showAddCateDialog">添加分類</el-button>
  </el-col>
</el-row>
......
<!-- 添加分類對(duì)話框 -->
<el-dialog title="添加分類" :visible.sync="addCateDialogVisible" width="50%"  @close="addCateDialogClosed">
  <!-- 添加分類表單 -->
  <el-form :model="addCateForm" :rules="addCateFormRules" ref="addCateFormRuleForm" label-width="100px">
    <el-form-item label="分類名稱" prop="cat_name">
      <el-input v-model="addCateForm.cat_name"></el-input>
    </el-form-item>
    <el-form-item label="父級(jí)分類" prop="cat_pid">
      
    </el-form-item>
  </el-form>
  <span slot="footer" class="dialog-footer">
    <el-button @click="addCateDialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="addCate">確 定</el-button>
  </span>
</el-dialog>


//用來(lái)顯示或隱藏添加分類對(duì)話框
addCateDialogVisible: false,
//添加分類的表單數(shù)據(jù)對(duì)象
addCateForm:{
  //分類名稱
  cat_name:'',
  //添加分類的父級(jí)id鸯匹,0則表示父級(jí)為0.添加一級(jí)分類
  cat_pid:0,
  //添加分類的等級(jí),0則表示添加一級(jí)分類
  cat_level:0
},
//添加分類校驗(yàn)規(guī)則
addCateFormRules:{
  //驗(yàn)證規(guī)則
  cat_name:[ {required:true , message:'請(qǐng)輸入分類名稱',trigger:'blur'} ]
},
//保存1,2級(jí)父級(jí)分類的列表
parentCateList:[]
.......
showAddCateDialog() {
  //調(diào)用getParentCateList獲取分類列表
  this.getParentCateList()
  //顯示添加分類對(duì)話框
  this.addCateDialogVisible = true
},
async getParentCateList(){
  //獲取父級(jí)分類數(shù)據(jù)列表
  const { data: res } = await this.$http.get('categories', {
    params: {type:2}
  })

  if (res.meta.status !== 200) {
    return this.$message.error('獲取商品分類列表數(shù)據(jù)失敗')
  }
  this.parentCateList = res.data
}

添加級(jí)聯(lián)菜單顯示父級(jí)分類
先導(dǎo)入Cascader組件,并注冊(cè)
然后添加使用級(jí)聯(lián)菜單組件:

<el-form-item label="父級(jí)分類" prop="cat_pid">
  <!-- expandTrigger='hover'(鼠標(biāo)懸停觸發(fā)級(jí)聯(lián)) v-model(設(shè)置級(jí)聯(lián)菜單綁定數(shù)據(jù)) :options(指定級(jí)聯(lián)菜單數(shù)據(jù)源)  :props(用來(lái)配置數(shù)據(jù)顯示的規(guī)則) 
  clearable(提供“X”號(hào)完成刪除文本功能) change-on-select(是否可以選中任意一級(jí)的菜單) -->
  <el-cascader expandTrigger='hover' v-model="selectedKeys" :options="parentCateList" :props="cascaderProps" @change="parentCateChange" clearable change-on-select></el-cascader>
</el-form-item>

添加數(shù)據(jù)
//配置級(jí)聯(lián)菜單中數(shù)據(jù)如何展示
cascaderProps:{
  value:'cat_id',
  label:'cat_name',
  children:'children',
  expandTrigger:'hover'
},
//綁定用戶選擇的分類值
selectedKeys:[]
.....
methods:{
  .....
  parentCateChange(){
    //級(jí)聯(lián)菜單中選擇項(xiàng)發(fā)生變化時(shí)觸發(fā)
    console.log(this.selectedKeys)
    //如果用戶選擇了父級(jí)分類
    if(this.selectedKeys.length > 0){
      //則將數(shù)組中的最后一項(xiàng)設(shè)置為父級(jí)分類
      this.addCateForm.cat_pid = this.selectedKeys[this.selectedKeys.length - 1]
      //level也要跟著發(fā)生變化
      this.addCateForm.cat_level = this.selectedKeys.length
      return
    }else{
      this.addCateForm.cat_pid = 0
      this.addCateForm.cat_level = 0
      return
    }
  },
  addCateDialogClosed(){
    //當(dāng)關(guān)閉添加分類對(duì)話框時(shí)茫藏,重置表單
    this.$refs.addCateFormRef.resetFields()
    this.selectedKeys = [];
    this.addCateForm.cat_pid = 0
    this.addCateForm.cat_level = 0
  },
  addCate() {
    //點(diǎn)擊確定,完成添加分類
    console.log(this.addCateForm)
    this.$refs.addCateFormRef.validate(async valid => {
      if (!valid) return
      //發(fā)送請(qǐng)求完成添加分類
      const { data: res } = await this.$http.post(
        'categories',
        this.addCateForm
      )

      if (res.meta.status !== 201) {
        return this.$message.error('添加分類失敗')
      }

      this.$message.success('添加分類成功')
      this.getCateList()
      this.addCateDialogVisible = false
    })
  }
}

I.推送代碼

制作完添加分類之后薇芝,將代碼提交到倉(cāng)庫(kù)蓬抄,推送到碼云,將goods_cate分支合并到master
git add .
git commit -m '完成商品分類'
git push
git checkout master
git merge goods_cate

2.參數(shù)管理

只允許給三級(jí)分類內(nèi)容設(shè)置參數(shù),參數(shù)分為動(dòng)態(tài)參數(shù)和靜態(tài)參數(shù)屬性

A.添加子級(jí)組件

添加Params.vue子組件夯到,并在router.js中引入該組件并設(shè)置路由規(guī)則

import Params from './components/goods/Params.vue'
......
path: '/home', component: Home, redirect: '/welcome', children: [
  { path: "/welcome", component: Welcome },
  { path: "/users", component: Users },
  { path: "/rights", component: Rights },
  { path: "/roles", component: Roles  },
  { path: "/categories", component: Cate  },
  { path: "/params", component: Params  }
]

B.完成組件基本布局

完成Params.vue組件的基本布局
其中警告提示信息使用了el-alert嚷缭,在element.js引入該組件并注冊(cè)

<template>
    <div>
        <h3>分類參數(shù)</h3>
        <!-- 面包屑導(dǎo)航 -->
        <el-breadcrumb separator="/">
            <el-breadcrumb-item :to="{ path: '/home' }">首頁(yè)</el-breadcrumb-item>
            <el-breadcrumb-item>商品管理</el-breadcrumb-item>
            <el-breadcrumb-item>分類參數(shù)</el-breadcrumb-item>
        </el-breadcrumb>
        <!-- 卡片視圖區(qū)域 -->
        <el-card>
            <!-- 警告區(qū)域 :closable="false"(是否展示“X”號(hào)) show-icon(顯示圖標(biāo)) -->
            <el-alert title="注意:只允許為第三級(jí)分類設(shè)置相關(guān)參數(shù)" type="warning" :closable="false" show-icon>
            </el-alert>

            <!-- 選擇商品分類區(qū)域 -->
            <el-row class="cat_opt">
                <el-col>
                    <span>選擇商品分類:</span>
                    <!-- 選擇商品分類的級(jí)聯(lián)選擇框 -->
                </el-col>
                <el-col></el-col>
            </el-row>
        </el-card>
    </div>
</template>

C.完成級(jí)聯(lián)選擇框

完成商品分類級(jí)聯(lián)選擇框

<!-- 選擇商品分類區(qū)域 -->
<el-row class="cat_opt">
    <el-col>
        <span>選擇商品分類:</span>
        <!-- 選擇商品分類的級(jí)聯(lián)選擇框 -->
        <el-cascader expandTrigger='hover' v-model="selectedCateKeys" :options="cateList" :props="cateProps" @change="handleChange" clearable></el-cascader>
    </el-col>
    <el-col></el-col>
</el-row>
......
<script>
export default {
  data() {
    return {
        //分類列表
        cateList:[],
        //用戶在級(jí)聯(lián)下拉菜單中選中的分類id
        selectedCateKeys:[],
        //配置級(jí)聯(lián)菜單中數(shù)據(jù)如何展示
        cateProps: {
            value: 'cat_id',
            label: 'cat_name',
            children: 'children'
        }
    }
  },
  created() {
      this.getCateList()
  },
  methods: {
      async getCateList(){
        //獲取所有的商品分類列表
        const { data: res } = await this.$http.get('categories')

        if (res.meta.status !== 200) {
            return this.$message.error('獲取分類數(shù)據(jù)失敗')
        }
        //將數(shù)據(jù)列表賦值給cateList
        this.cateList = res.data
        // //保存總數(shù)據(jù)條數(shù)
        // this.total = res.data.total
        //   console.log(res.data);
      },
      handleChange(){
        //當(dāng)用戶在級(jí)聯(lián)菜單中選擇內(nèi)容改變時(shí)觸發(fā)
        console.log(this.selectedCateKeys);
      }
  }
}
</script>

D.展示參數(shù)

展示動(dòng)態(tài)參數(shù)數(shù)據(jù)以及靜態(tài)屬性數(shù)據(jù)

<!-- tab頁(yè)簽區(qū)域 -->
<el-tabs v-model="activeName" @tab-click="handleTabClick">
  <!-- 添加動(dòng)態(tài)參數(shù)的面板 將標(biāo)簽頁(yè)改為many -->
  <el-tab-pane label="動(dòng)態(tài)參數(shù)" name="many">
    <el-button size="mini" type="primary" :disabled="isButtonDisabled">添加參數(shù)</el-button>
    <!-- 動(dòng)態(tài)參數(shù)表格 -->
    <el-table :data="manyTableData" border stripe>
      <!-- 展開(kāi)行 -->
      <el-table-column type="expand"></el-table-column>
      <!-- 索引列 -->
      <el-table-column type="index"></el-table-column>
      <el-table-column label="參數(shù)名稱" prop="attr_name"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" type="primary" icon="el-icon-edit">編輯</el-button>
          <el-button size="mini" type="danger" icon="el-icon-delete">刪除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </el-tab-pane>
  <!-- 添加靜態(tài)屬性的面板 將標(biāo)簽頁(yè)改為only -->
  <el-tab-pane label="靜態(tài)屬性" name="only">
    <el-button size="mini" type="primary" :disabled="isButtonDisabled">添加屬性</el-button>
    <!-- 靜態(tài)屬性表格 -->
    <el-table :data="onlyTableData" border stripe>
      <!-- 展開(kāi)行 -->
      <el-table-column type="expand"></el-table-column>
      <!-- 索引列 -->
      <el-table-column type="index"></el-table-column>
      <el-table-column label="屬性名稱" prop="attr_name"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" type="primary" icon="el-icon-edit">編輯</el-button>
          <el-button size="mini" type="danger" icon="el-icon-delete">刪除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </el-tab-pane>

</el-tabs>


<script>
export default {
  data() {
    return {
      ......
      //tab頁(yè)簽激活顯示的頁(yè)簽項(xiàng)
      activeName: 'many',
      //用來(lái)保存動(dòng)態(tài)參數(shù)數(shù)據(jù)
      manyTableData: [],
      //用來(lái)保存靜態(tài)屬性數(shù)據(jù)
      onlyTableData: []  
    }
  methods: {
    .......
    async handleChange() {
      //當(dāng)用戶在級(jí)聯(lián)菜單中選擇內(nèi)容改變時(shí)觸發(fā)
      console.log(this.selectedCateKeys)
      //發(fā)送請(qǐng)求,根據(jù)用戶選擇的三級(jí)分類和面板獲取參數(shù)數(shù)據(jù)
      const { data: res } = await this.$http.get(
        `categories/${this.cateId}/attributes`,
        { params: { sel: this.activeName } }
      )
      if (res.meta.status !== 200) {
        return this.$message.error('獲取參數(shù)列表數(shù)據(jù)失敗')
      }

      console.log(res.data)
      if (this.activeName === 'many') {
        //獲取的是動(dòng)態(tài)參數(shù)
        this.manyTableData = res.data
      } else if (this.activeName === 'only') {
        //獲取的是靜態(tài)屬性
        this.onlyTableData = res.data
      }
    },
    handleTabClick() {
      console.log(this.activeName)
      this.handleChange()
    }
  },
  computed: {
    //添加計(jì)算屬性用來(lái)獲取按鈕禁用與否
    isButtonDisabled() {
      return this.selectedCateKeys.length !== 3
    },
    //獲取選中的三級(jí)分類id
    cateId() {
      if (this.selectedCateKeys.length === 3) {
        return this.selectedCateKeys[this.selectedCateKeys.length - 1]
      }
      return null
    }
  }

E.添加參數(shù)

完成添加參數(shù)或?qū)傩?/p>

<!-- 添加參數(shù)或?qū)傩詫?duì)話框 -->
<el-dialog :title="'添加'+titleText" :visible.sync="addDialogVisible" width="50%" @close="addDialogClosed">
  <!-- 添加表單 -->
  <el-form :model="addForm" :rules="addFormRules" ref="addFormRef" label-width="100px">
    <el-form-item :label="titleText" prop="attr_name">
      <el-input v-model="addForm.attr_name"></el-input>
    </el-form-item>
  </el-form>
  <span slot="footer" class="dialog-footer">
    <el-button @click="addDialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="addParams">確 定</el-button>
  </span>
</el-dialog>

export default {
  data() {
    return {
      .......
      //控制添加參數(shù).屬性對(duì)話框的顯示或隱藏
      addDialogVisible: false,
      //添加參數(shù)的表單數(shù)據(jù)對(duì)象
      addForm: {
        attr_name: ''
      },
      //添加表單驗(yàn)證規(guī)則
      addFormRules: {
        attr_name: [{ required: true, message: '請(qǐng)輸入名稱', trigger: 'blur' }]
      }
    }
  },methods: {
    .......
    addParams() {
      //當(dāng)用戶點(diǎn)擊對(duì)話框中的確定時(shí)耍贾,校驗(yàn)表單
      this.$refs.addFormRef.validate(async valid => {
        //校驗(yàn)不通過(guò)阅爽,return
        if (!valid) return
        //校驗(yàn)通過(guò),發(fā)送請(qǐng)求完成添加參數(shù)或者屬性
        const { data: res } = this.$http.post(`categories/${this.cateId}/attributes`,
          { 
            attr_name: this.addForm.attr_name, 
            attr_sel: this.activeName,
            attr_vals: "a,b,c" 
          }
        )

        console.log(res)
        if (res.meta.status !== 201) {
          return this.$message.error('添加' + this.titleText + '數(shù)據(jù)失敗')
        }
        this.$message.success('添加' + this.titleText + '數(shù)據(jù)成功')
        this.addDialogVisible = false
        this.getCateList()
      })
    }
  }

F.編輯參數(shù)

完成編輯參數(shù)或?qū)傩?/p>

<!-- 修改參數(shù)或?qū)傩詫?duì)話框 -->
<el-dialog :title="'修改'+titleText" :visible.sync="editDialogVisible" width="50%" @close="editDialogClosed">
  <!-- 添加表單 -->
  <el-form :model="editForm" :rules="editFormRules" ref="editFormRef" label-width="100px">
    <el-form-item :label="titleText" prop="attr_name">
      <el-input v-model="editForm.attr_name"></el-input>
    </el-form-item>
  </el-form>
  <span slot="footer" class="dialog-footer">
    <el-button @click="editDialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="editParams">確 定</el-button>
  </span>
</el-dialog>

export default {
  data() {
    return {
      .......
      //控制修改參數(shù).屬性對(duì)話框的顯示或隱藏
      editDialogVisible:false,
      //修改參數(shù).屬性對(duì)話框中的表單
      editForm:{
        attr_name:''
      },
      //修改表單的驗(yàn)證規(guī)則
      editFormRules:{
        attr_name:[
          { required: true, message: '請(qǐng)輸入名稱', trigger: 'blur' }
        ]
      }
    }
  },methods: {
    .......
    async showEditDialog(attr_id){
      //發(fā)起請(qǐng)求獲取需要修改的那個(gè)參數(shù)數(shù)據(jù)
      const {data:res} = await this.$http.get(`categories/${this.cateId}/attributes/${attr_id}`,
      {params:{ attr_sel:this.activeName }})
      if (res.meta.status !== 200) {
        return this.$message.error('獲取參數(shù)數(shù)據(jù)失敗')
      }
      this.editForm = res.data;
      //顯示修改參數(shù).屬性對(duì)話框
      this.editDialogVisible = true;
    },
    editDialogClosed(){
      //當(dāng)關(guān)閉修改參數(shù).屬性對(duì)話框時(shí)
      this.$refs.editFormRef.resetFields()
    },
    editParams(){
      //驗(yàn)證表單
      this.$refs.editFormRef.validate(async valid => {
        if(!valid) return;

        //發(fā)送請(qǐng)求完成修改
        const {data:res} = await this.$http.put(`categories/${this.cateId}/attributes/${this.editForm.attr_id}`,
        {attr_name:this.editForm.attr_name,attr_sel:this.activeName})

        if (res.meta.status !== 200) {
          return this.$message.error('獲取參數(shù)數(shù)據(jù)失敗')
        }
        this.$message.success('修改' + this.titleText + '數(shù)據(jù)成功')
        this.editDialogVisible = false
        this.handleChange();
      })
    }
  }

G.刪除參數(shù)

刪除參數(shù)或?qū)傩?/p>

給兩個(gè)刪除按鈕添加事件
<el-button size="mini" type="danger" icon="el-icon-delete" @click="removeParams(scope.row.attr_id)">刪除</el-button>
<el-button size="mini" type="danger" icon="el-icon-delete" @click="removeParams(scope.row.attr_id)">刪除</el-button>

添加對(duì)應(yīng)的事件處理函數(shù)
async removeParams(attr_id){
  //根據(jù)id刪除對(duì)應(yīng)的參數(shù)或?qū)傩?  //彈窗提示用戶是否要?jiǎng)h除
  const confirmResult = await this.$confirm(
    '請(qǐng)問(wèn)是否要?jiǎng)h除該'+this.titleText,
    '刪除提示',
    {
      confirmButtonText: '確認(rèn)刪除',
      cancelButtonText: '取消',
      type: 'warning'
    }
  ).catch(err => err)
  //如果用戶點(diǎn)擊確認(rèn)荐开,則confirmResult 為'confirm'
  //如果用戶點(diǎn)擊取消, 則confirmResult獲取的就是catch的錯(cuò)誤消息'cancel'
  if (confirmResult != 'confirm') {
    return this.$message.info('已經(jīng)取消刪除')
  }

  //沒(méi)有取消就是要?jiǎng)h除优床,發(fā)送請(qǐng)求完成刪除
  const {data:res} = await this.$http.delete(`categories/${this.cateId}/attributes/${attr_id}`)

  if (res.meta.status !== 200) {
    return this.$message.error('刪除參數(shù)數(shù)據(jù)失敗')
  }
  this.$message.success('刪除' + this.titleText + '數(shù)據(jù)成功')
  this.handleChange()
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市誓焦,隨后出現(xiàn)的幾起案子胆敞,更是在濱河造成了極大的恐慌,老刑警劉巖杂伟,帶你破解...
    沈念sama閱讀 219,427評(píng)論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件移层,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡赫粥,警方通過(guò)查閱死者的電腦和手機(jī)观话,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,551評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門(mén),熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)越平,“玉大人频蛔,你說(shuō)我怎么就攤上這事∏嘏眩” “怎么了晦溪?”我有些...
    開(kāi)封第一講書(shū)人閱讀 165,747評(píng)論 0 356
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)挣跋。 經(jīng)常有香客問(wèn)我三圆,道長(zhǎng),這世上最難降的妖魔是什么避咆? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,939評(píng)論 1 295
  • 正文 為了忘掉前任舟肉,我火速辦了婚禮,結(jié)果婚禮上查库,老公的妹妹穿的比我還像新娘路媚。我一直安慰自己,他們只是感情好樊销,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,955評(píng)論 6 392
  • 文/花漫 我一把揭開(kāi)白布整慎。 她就那樣靜靜地躺著脏款,像睡著了一般。 火紅的嫁衣襯著肌膚如雪院领。 梳的紋絲不亂的頭發(fā)上弛矛,一...
    開(kāi)封第一講書(shū)人閱讀 51,737評(píng)論 1 305
  • 那天,我揣著相機(jī)與錄音比然,去河邊找鬼丈氓。 笑死,一個(gè)胖子當(dāng)著我的面吹牛强法,可吹牛的內(nèi)容都是我干的万俗。 我是一名探鬼主播,決...
    沈念sama閱讀 40,448評(píng)論 3 420
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼饮怯,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼闰歪!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起蓖墅,我...
    開(kāi)封第一講書(shū)人閱讀 39,352評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤库倘,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后论矾,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體教翩,經(jīng)...
    沈念sama閱讀 45,834評(píng)論 1 317
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,992評(píng)論 3 338
  • 正文 我和宋清朗相戀三年贪壳,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了饱亿。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,133評(píng)論 1 351
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡闰靴,死狀恐怖彪笼,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情蚂且,我是刑警寧澤配猫,帶...
    沈念sama閱讀 35,815評(píng)論 5 346
  • 正文 年R本政府宣布,位于F島的核電站膘掰,受9級(jí)特大地震影響章姓,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜识埋,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,477評(píng)論 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望零渐。 院中可真熱鬧窒舟,春花似錦、人聲如沸诵盼。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 32,022評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至洁墙,卻和暖如春蛹疯,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背热监。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 33,147評(píng)論 1 272
  • 我被黑心中介騙來(lái)泰國(guó)打工捺弦, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人孝扛。 一個(gè)月前我還...
    沈念sama閱讀 48,398評(píng)論 3 373
  • 正文 我出身青樓列吼,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親苦始。 傳聞我的和親對(duì)象是個(gè)殘疾皇子寞钥,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,077評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容

  • 文章分類 后臺(tái)文章分類列表頁(yè)模板導(dǎo)的詳細(xì)步驟建立數(shù)據(jù)表blog_category,并添加相應(yīng)的文章字段使用php ...
    JoyceZhao閱讀 1,708評(píng)論 0 12
  • ORA-00001: 違反唯一約束條件 (.) 錯(cuò)誤說(shuō)明:當(dāng)在唯一索引所對(duì)應(yīng)的列上鍵入重復(fù)值時(shí)陌选,會(huì)觸發(fā)此異常理郑。 O...
    我想起個(gè)好名字閱讀 5,320評(píng)論 0 9
  • 基于Vue的一些資料 內(nèi)容 UI組件 開(kāi)發(fā)框架 實(shí)用庫(kù) 服務(wù)端 輔助工具 應(yīng)用實(shí)例 Demo示例 element★...
    嘗了又嘗閱讀 1,154評(píng)論 0 1
  • Vue2.0+組件庫(kù)總結(jié) UI組件 element - 餓了么出品的Vue2的web UI工具套件 Vux - 基...
    szch閱讀 1,977評(píng)論 1 52
  • UI組件 element- 餓了么出品的Vue2的web UI工具套件 Vux- 基于Vue和WeUI的組件庫(kù) m...
    柴東啊閱讀 15,857評(píng)論 2 140