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. New1. Add a button 2. Add a new event in methods to open the pop-up window. **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. Modification2-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:
|
<<: How to use worm replication in Mysql data table
>>: VMware installation of Centos8 system tutorial diagram (command line mode)
The vue part is as follows: <template> <...
A few days ago, I watched a video of a foreign gu...
1. Description Earlier we talked about the instal...
Table of contents 1. Basic use of axio 2. How to ...
This article shares a draggable login box impleme...
Table of contents url module 1.parse method 2. fo...
Original article, please indicate the author and ...
This article example shares the specific code of ...
01. Command Overview The tr command can replace, ...
Table of contents Tutorial Series 1. Backup strat...
Combining the various problems I encountered in m...
How is the MySQL Select statement executed? I rec...
If you don't want to use javascript control, t...
Purpose: Allow the state data managed in vuex to ...