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

How to skip errors in mysql master-slave replication

1. Traditional binlog master-slave replication, s...

Specific implementation methods of MySQL table sharding and partitioning

Vertical table Vertical table splitting means spl...

Three ways to draw a heart shape with CSS

Below, we introduce three ways to draw heart shap...

Implementation of Docker private library

Installing and deploying a private Docker Registr...

Detailed explanation of creating and calling MySQL stored procedures

Table of contents Preface Stored Procedure: 1. Cr...

How to simulate enumeration with JS

Preface In current JavaScript, there is no concep...

Three ways to avoid duplicate insertion of data in MySql

Preface In the case of primary key conflict or un...

503 service unavailable error solution explanation

1. When you open the web page, 503 service unavai...

HTML Basics: The basic structure of HTML

The basic structure of HTML hypertext documents is...

How to install MySQL 5.7.17 and set the encoding to utf8 in Windows

download MySQL official download, select Windows ...

JS realizes picture digital clock

This article example shares the specific code of ...

How to use the debouce anti-shake function in Vue

Table of contents 1. Anti-shake function 2. Use d...

HTML structured implementation method

DIV+css structure Are you learning CSS layout? Sti...

Using js to implement the two-way binding function of data in Vue2.0

Object.defineProperty Understanding grammar: Obje...