Vue + element to dynamically display background data to options

Vue + element to dynamically display background data to options

need:

Implement dynamic display of option values ​​in the selector instead of hard-coded data. My role ID data is as follows:

insert image description here

Now we need to display these data requests on the option

The implementation is as follows:

Use the selector in element-ui:

<el-form-item label="Role ID:" prop="roleId">
    <el-select v-model="addUserForm.roleId" placeholder="Please select role ID">
      <el-option
          v-for="item in roleList"
          :key="item.value"
          :label="item.label"
          :value="item.value">
      </el-option>
    </el-select>
</el-form-item>

Customize an empty array in data:

insert image description here

Write the request to implement data in methods:

getroleList() {
   getRoleList(this.name).then(res => {
     let result = res.data.items;
     console.log("Get role list: " +JSON.stringify(this.roleList));
     result.forEach(element => {
     	this.roleList.push({label:element.name,value:element.name});
     });
     }).catch( error => {
       console.log(error);
  });
},

In created implementation display:

insert image description here

Where getRoleList is the get request I encapsulated:

insert image description here

The results are as follows:

insert image description here

This is the end of this article about how to use Vue + element to dynamically display background data to options. For more relevant Vue element dynamic options content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Vue+Element ui sets dynamic header operation according to the background return data
  • Vue+element uses dynamic loading routing to implement the operation of displaying the three-level menu page

<<:  Solve the problem of Linux FTP anonymous upload and download starting automatically

>>:  MySQL 8.0.11 Installation Guide for Mac

Recommend

CSS3 uses animation attributes to achieve cool effects (recommended)

animation-name animation name, can have multiple ...

A simple method to implement scheduled backup of MySQL database in Linux

Here are the detailed steps: 1. Check the disk sp...

Summary of several APIs or tips in HTML5 that cannot be missed

In previous blog posts, I have been focusing on so...

How to open a page in an iframe

Solution: Just set the link's target attribute...

How to pull the docker image to view the version

To view the version and tag of the image, you nee...

Implementation of importing and exporting docker images

Docker usage of gitlab gitlab docker Startup Comm...

Javascript Virtual DOM Detailed Explanation

Table of contents What is virtual dom? Why do we ...

Explain the difference between iframe and frame in HTML with examples

I don't know if you have used the frameset at...

Steps to build MHA architecture deployment in MySQL

Table of contents MAH 1. Introduction to MAH Arch...

How to use nginx to build a static resource server

Taking Windows as an example, Linux is actually t...

Implementation of static website layout in docker container

Server placement It is recommended to use cloud s...

Practical MySQL + PostgreSQL batch insert update insertOrUpdate

Table of contents 1. Baidu Encyclopedia 1. MySQL ...