欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue+elementui 實(shí)現(xiàn)新增和修改共用一個(gè)彈框的完整代碼

 更新時(shí)間:2021年06月08日 09:35:43   作者:Ao_min  
Element-Ul是餓了么前端團(tuán)隊(duì)推出的一款基于Vue.js 2.0 的桌面端UI框架,手機(jī)端有對(duì)應(yīng)框架是Mint UI ,今天給大家普及vue+elementui 實(shí)現(xiàn)新增和修改共用一個(gè)彈框的完整代碼,一起看看吧

element-ui是由餓了么前端團(tuán)隊(duì)推出的一套為開發(fā)者、設(shè)計(jì)師和產(chǎn)品經(jīng)理準(zhǔn)備的基于Vue.js 2.0的桌面組件庫,而手機(jī)端有對(duì)應(yīng)框架是 Mint UI 。整個(gè)ui風(fēng)格簡(jiǎn)約,很實(shí)用,同時(shí)也極大的提高了開發(fā)者的效率,是一個(gè)非常受歡迎的組件庫。

一、新增

1、新增按鈕

2、新增事件 在methods中,用來打開彈窗,
dialogVisible在data中定義使用有true或false來控制顯示彈框

**3、新增確定,彈框確定事件 ,新增和修改共用一個(gè)確定事件,使用id區(qū)別

**3、新增事件

調(diào)新增接口,判斷是否有id,沒有就調(diào)新增接口

二、修改

2-1、修改按鈕 ,表格行編輯按鈕使用scope.row拿到當(dāng)前行的數(shù)據(jù)

2-2、修改事件, 把當(dāng)前行數(shù)據(jù)賦值給表單,就把當(dāng)前行數(shù)據(jù)回顯出來了

2-3、修改事件

修改接口,判斷是否有id,有就調(diào)修改接口**

下面直接上代碼了

<template>
  <div>
    <!-- 面包屑導(dǎo)航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/Welcome' }">首頁</el-breadcrumb-item>
      <el-breadcrumb-item>權(quán)限管理</el-breadcrumb-item>
      <el-breadcrumb-item>角色列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片 -->
    <el-card class="box-card">
      <!-- 新增按鈕 -->
      <el-row :gutter="20">
        <el-col :span="6">
          <div class="grid-content bg-purple"></div>
          <el-button type="primary" @click="onhandAdd">添加角色</el-button>
        </el-col>
      </el-row>
      <!-- 表格 -->
      <el-table :data="tableData" border="" style="width: 100%">
        <el-table-column type="expand">
          <template slot-scope="scope">
            <el-row
              :class="['bdbottom',i1 === 0? 'bdtop' : '', 'vcenter'] "
              :gutter="20"
              :span="6"
              v-for="(item_ong,i1) in scope.row.children"
              :key="item_ong.id"
            >
              <!-- 一級(jí) -->
              <el-col :span="5">
                <el-tag>{{item_ong.authName}}</el-tag>
                <i class="el-icon-caret-right"></i>
              </el-col>
              <!-- 二級(jí)和三級(jí) -->
              <el-col :span="19">
                <!-- 二級(jí)權(quán)限 -->
                <el-row v-for="(item_two,i2) in item_ong.children" :key="i2">
                  <el-col :span="6">
                    <el-tag type="success">{{item_two.authName}}</el-tag>
                    <i class="el-icon-caret-right"></i>
                  </el-col>
                  <el-col :span="18">
                    <el-tag
                      type="warning"
                      v-for="(item_three,i3) in item_two.children"
                      :key="i3"
                    >{{item_three.authName}}</el-tag>
                    <i class="el-icon-caret-right"></i>
                  </el-col>
                </el-row>
              </el-col>
            </el-row>
          </template>
        </el-table-column>
        <el-table-column label="#" type="index" width="80"></el-table-column>
        <el-table-column label="角色名稱" prop="roleName"></el-table-column>
        <el-table-column label="角色描述" prop="roleDesc"></el-table-column>
        <el-table-column label="操作" prop="id">
          <template slot-scope="scope">
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="small"
              @click="handleEdit(scope.$index, scope.row)"
            >編輯</el-button>
            <el-button type="warning" icon="el-icon-delete" size="small">刪除</el-button>
            <el-button type="danger" icon="el-icon-edit" size="small">權(quán)限</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <!-- 新增編輯彈框 -->
    <el-dialog
      :title="addtitle"
      :visible.sync="dialogVisible"
      width="40%"
      :before-close="handleClose"
    >
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="refRuleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="角色名稱" prop="roleName">
          <el-input v-model="ruleForm.roleName"></el-input>
        </el-form-item>
        <el-form-item label="角色描述" prop="roleDesc">
          <el-input v-model="ruleForm.roleDesc"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisibleConfirm">確 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: [],
      dialogVisible: false,
      addtitle: "添加角色",
      ruleForm: {
        roleName: "",
        roleDesc: ""
      },
      allid: "",
      // 驗(yàn)證規(guī)則
      rules: {
        roleName: [
          { required: true, message: "請(qǐng)輸入角色名稱", trigger: "blur" },
          { min: 3, max: 5, message: "長(zhǎng)度在 3 到 5 個(gè)字符", trigger: "blur" }
        ],
        roleDesc: [{ required: true, message: "角色描述", trigger: "blur" }]
      }
    };
  },
  created() {
    this.tabList();
  },
  methods: {
    //   表格接口列表
    tabList() {
      this.$api.jurisdiction.rolelist().then(res => {
        console.log(res.data.data, "]]]]]]]");
        this.tableData = res.data.data;
      });
    },
    // 新增
    onhandAdd() {
      this.dialogVisible = true;
    },
    handleClose(done) {
      this.dialogVisible = false;
    },
    // 編輯
    handleEdit(index, row) {
      console.log(index, row.id);
      this.dialogVisible = true;   //顯示彈框
      this.ruleForm = row;         //row當(dāng)前行數(shù)據(jù),把當(dāng)前行的數(shù)據(jù)賦值給 表單
      this.allid = row.id;         //把id存全局
    },
    // 確定
    dialogVisibleConfirm() {
      // 新增接口
      if (!this.allid) {
        this.$api.jurisdiction.addrole(this.ruleForm)
          .then(res => {
            // console.log(res,"新增")
            this.$message.success("添加成功");     //新增成功消息提示
            this.$refs.refRuleForm.resetFields(); //清空表格數(shù)據(jù)
            this.dialogVisible = false;           //關(guān)閉彈框
            this.tabList();                       //刷新列表
          })
          .catch(res => {
            this.$message.error("添加失敗");
          });
      } else {
        // 修改接口
        let id = this.allid
        let params = {
          roleName:this.ruleForm.roleName,
          roleDesc:this.ruleForm.roleDesc,
        }
        this.$api.jurisdiction.edtrole(id,params)
          .then(res => {
            console.log(res,"修改")
            this.$message.success("修改成功");
            this.$refs.refRuleForm.resetFields();
            this.dialogVisible = false;
            this.tabList();
          })
          .catch(res => {
            this.$message.error("修改失敗");
          });
      }
    }
  }
};
</script>

<style scoped>
.bdtop {
  border-top: 1px solid #eee;
  padding-top: 10px;
}
.bdbottom {
  border-bottom: 1px solid #eee;
  padding-bottom: 10px;
  padding-top: 10px;
}
.el-tag {
  margin: 10px 0px;
}
.vcenter {
  display: flex;
  align-items: center;
}
</style>

以上就是vue+elementui 實(shí)現(xiàn)新增和修改共用一個(gè)彈框的完整代碼的詳細(xì)內(nèi)容,更多關(guān)于vue elementui彈框的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • 深入Vue-Router路由嵌套理解

    深入Vue-Router路由嵌套理解

    這篇文章主要介紹了深入Vue-Router路由嵌套理解,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-08-08
  • 帶你一文了解Vue生命周期鉤子

    帶你一文了解Vue生命周期鉤子

    生命周期鉤子又被叫做生命周期時(shí)間,生命周期函數(shù),生命周期鉤子就是vue生命周期中出發(fā)的各類事件,這些事件被稱為生命周期鉤子,下面這篇文章主要給大家介紹了關(guān)于Vue生命周期鉤子的相關(guān)資料,需要的朋友可以參考下
    2022-06-06
  • vue進(jìn)度條組件實(shí)現(xiàn)代碼(可拖拽可點(diǎn)擊)

    vue進(jìn)度條組件實(shí)現(xiàn)代碼(可拖拽可點(diǎn)擊)

    在日常開發(fā)中隨著需求的個(gè)性化,邏輯的復(fù)雜化,自定義組件也變得越來越常見,這篇文章主要給大家介紹了關(guān)于vue進(jìn)度條組件實(shí)現(xiàn)(可拖拽可點(diǎn)擊)的相關(guān)資料,需要的朋友可以參考下
    2023-12-12
  • Vue中子組件的顯示與隱藏方式

    Vue中子組件的顯示與隱藏方式

    這篇文章主要介紹了Vue中子組件的顯示與隱藏方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-09-09
  • vue-router:嵌套路由的使用方法

    vue-router:嵌套路由的使用方法

    本篇文章主要介紹了vue-router:嵌套路由的使用方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-02-02
  • vue elementui el-form rules動(dòng)態(tài)驗(yàn)證的實(shí)例代碼詳解

    vue elementui el-form rules動(dòng)態(tài)驗(yàn)證的實(shí)例代碼詳解

    在使用elementUI el-form 中,對(duì)于業(yè)務(wù)不同的時(shí)候可能會(huì)產(chǎn)生不同表單結(jié)構(gòu),但是都是存在同一個(gè)表單控件el-form中。這篇文章主要介紹了vue elementui el-form rules動(dòng)態(tài)驗(yàn)證的實(shí)例代碼,需要的朋友可以參考下
    2019-05-05
  • VUE PC端可拖動(dòng)懸浮按鈕的實(shí)現(xiàn)代碼

    VUE PC端可拖動(dòng)懸浮按鈕的實(shí)現(xiàn)代碼

    這篇文章主要介紹了VUE PC端可拖動(dòng)懸浮按鈕的實(shí)現(xiàn)代碼,通過實(shí)例代碼介紹了父頁面引用的方法,本文結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2024-02-02
  • vue使用keep-alive后清除緩存的方法

    vue使用keep-alive后清除緩存的方法

    這篇文章主要給大家介紹了關(guān)于vue使用keep-alive后清除緩存的相關(guān)資料,這個(gè)問題在我們?nèi)粘9ぷ髦薪?jīng)常會(huì)用到,本文通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2021-08-08
  • 解析vue?3.0?使用axios庫發(fā)起?post?get?的配置過程

    解析vue?3.0?使用axios庫發(fā)起?post?get?的配置過程

    get post 請(qǐng)求開發(fā)中最普通最常見的請(qǐng)求方式但是在vue中如何實(shí)現(xiàn)呢 這里記錄一下配置過程,對(duì)vue?使用axios發(fā)起?post?get配置過程感興趣的朋友一起看看吧
    2022-05-05
  • Vue使用babel-polyfill兼容IE解決白屏及語法報(bào)錯(cuò)問題

    Vue使用babel-polyfill兼容IE解決白屏及語法報(bào)錯(cuò)問題

    這篇文章主要介紹了Vue使用babel-polyfill兼容IE解決白屏及語法報(bào)錯(cuò)問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-03-03

最新評(píng)論