vue+elementui implements the complete code of adding and modifying a shared bullet box

vue+elementui implements the complete code of adding and modifying a shared bullet box

element-ui is a desktop component library based on Vue.js 2.0 launched by the front-end team of Ele.me for developers, designers and product managers, while the corresponding framework for mobile phones is Mint UI. The entire UI style is simple and practical, and it also greatly improves the efficiency of developers. It is a very popular component library.

1. New

1. Add a button

2. Add a new event in methods to open the pop-up window.
dialogVisible is defined in data and is used with true or false to control the display of the pop-up box

**3. Add confirmation, pop-up confirmation event, add and modify share the same confirmation event, use id to distinguish

**3. New events

Call the newly added interface to determine whether there is an id. If not, call the newly added interface

II. Modification

2-1. Modify button, table row edit button uses scope.row to get the data of the current row

2-2. Modify the event, assign the current row data to the form, and then the current row data will be echoed out

2-3. Modify events

Modify the interface to determine whether there is an id, if there is, call the modification interface**

The following is the code directly

<template>
  <div>
    <!-- Breadcrumb navigation -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/Welcome' }">Home</el-breadcrumb-item>
      <el-breadcrumb-item>Permission Management</el-breadcrumb-item>
      <el-breadcrumb-item>List of roles</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- Cards -->
    <el-card class="box-card">
      <!-- Add button-->
      <el-row :gutter="20">
        <el-col :span="6">
          <div class="grid-content bg-purple"></div>
          <el-button type="primary" @click="onhandAdd">Add role</el-button>
        </el-col>
      </el-row>
      <!-- Table -->
      <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"
            >
              <!-- Level 1 -->
              <el-col :span="5">
                <el-tag>{{item_ong.authName}}</el-tag>
                <i class="el-icon-caret-right"></i>
              </el-col>
              <!-- Secondary and tertiary levels -->
              <el-col :span="19">
                <!-- Second level permissions-->
                <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="Role Name" prop="roleName"></el-table-column>
        <el-table-column label="Role Description" prop="roleDesc"></el-table-column>
        <el-table-column label="operation" prop="id">
          <template slot-scope="scope">
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="small"
              @click="handleEdit(scope.$index, scope.row)"
            >Edit</el-button>
            <el-button type="warning" icon="el-icon-delete" size="small">Delete</el-button>
            <el-button type="danger" icon="el-icon-edit" size="small">Permissions</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <!-- Added edit pop-up box-->
    <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="Role Name" prop="roleName">
          <el-input v-model="ruleForm.roleName"></el-input>
        </el-form-item>
        <el-form-item label="Role Description" 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">Cancel</el-button>
        <el-button type="primary" @click="dialogVisibleConfirm">Confirm</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: [],
      dialogVisible: false,
      addtitle: "Add role",
      ruleForm: {
        roleName: "",
        roleDesc: ""
      },
      allid: "",
      // Validation rules: {
        roleName: [
          { required: true, message: "Please enter a character name", trigger: "blur" },
          { min: 3, max: 5, message: "Length is between 3 and 5 characters", trigger: "blur" }
        ],
        roleDesc: [{ required: true, message: "Role description", trigger: "blur" }]
      }
    };
  },
  created() {
    this.tabList();
  },
  methods: {
    // Table interface list tabList() {
      this.$api.jurisdiction.rolelist().then(res => {
        console.log(res.data.data, "]]]]]]]]");
        this.tableData = res.data.data;
      });
    },
    // Add onhandAdd() {
      this.dialogVisible = true;
    },
    handleClose(done) {
      this.dialogVisible = false;
    },
    // Edit handleEdit(index, row) {
      console.log(index, row.id);
      this.dialogVisible = true; //Show the pop-up box this.ruleForm = row; //row current row data, assign the current row data to the form this.allid = row.id; //Store the id globally},
    // Confirm dialogVisibleConfirm() {
      // New interface if (!this.allid) {
        this.$api.jurisdiction.addrole(this.ruleForm)
          .then(res => {
            // console.log(res,"new")
            this.$message.success("Added successfully"); //Added successful message prompt this.$refs.refRuleForm.resetFields(); //Clear table data this.dialogVisible = false; //Close the pop-up box this.tabList(); //Refresh the list })
          .catch(res => {
            this.$message.error("Add failed");
          });
      } else {
        // Modify the interface 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,"modify")
            this.$message.success("Modification successful");
            this.$refs.refRuleForm.resetFields();
            this.dialogVisible = false;
            this.tabList();
          })
          .catch(res => {
            this.$message.error("Modification failed");
          });
      }
    }
  }
};
</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>

The above is the details of the complete code for adding and modifying a shared pop-up box using vue+elementui. For more information about vue elementui pop-up box, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • Vue+elementui realizes clicking on a cell in the table to trigger an event--a bullet box
  • Solve the triggering problem of change event when vue elementUI uses el-select
  • VUE-ElementUI custom Loading chart operation
  • Table highlighting or font color change operation in vue+elementUI
  • vue+ElementUI closes the dialog box, clears the verification, and clears the form operation

<<:  How to use worm replication in Mysql data table

>>:  VMware installation of Centos8 system tutorial diagram (command line mode)

Recommend

Solution to the error reported by Mysql systemctl start mysqld

Error message: Job for mysqld.service failed beca...

Introduction to HTML page source code layout_Powernode Java Academy

Introduction to HTML page source code layout This...

Detailed explanation of the use of Teleport in Vue3

Table of contents Purpose of Teleport How Telepor...

How to update, package, and upload Docker containers to Alibaba Cloud

This time, we will try to package the running con...

Detailed explanation of Nginx forwarding socket port configuration

Common scenarios for Nginx forwarding socket port...

Detailed explanation of Vue-Jest automated testing basic configuration

Table of contents Install Configuration Common Mi...

Detailed explanation of html printing related operations and implementation

The principle is to call the window.print() metho...

Summary of common problems and solutions in Vue (recommended)

There are some issues that are not limited to Vue...

Let's talk briefly about the changes in setup in vue3.0 sfc

Table of contents Preface Standard sfc writing me...

Summary of Docker Data Storage

Before reading this article, I hope you have a ba...

How to install Docker and configure Alibaba Cloud Image Accelerator

Docker Installation There is no need to talk abou...

Introduction to ApplicationHost.config (IIS storage configuration area file)

For a newly created website, take ASP.NET MVC5 as...

Briefly describe the MySQL InnoDB storage engine

Preface: The storage engine is the core of the da...

JavaScript+html to implement front-end page sliding verification (2)

This article example shares the specific code of ...