need:Implement dynamic display of option values in the selector instead of hard-coded data. My role ID data is as follows: 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: 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: Where getRoleList is the get request I encapsulated: The results are as follows: 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:
|
<<: Solve the problem of Linux FTP anonymous upload and download starting automatically
>>: MySQL 8.0.11 Installation Guide for Mac
A very common scenario in react projects: const [...
This article shares a native JS implementation of...
Recently, there is a requirement for uploading pi...
Recently, when I was writing a WeChat applet, the...
Develop a number guessing game that randomly sele...
Table of contents forEach() Method How to jump ou...
Today, let's talk about how to use js to achi...
1. Apache static resource cross-domain access Fin...
Table of contents Why do we need garbage collecti...
Table of contents How to deploy MySQL service usi...
Preface In practice, we may encounter such a prob...
yum command Yum (full name Yellow dog Updater, Mo...
Preface Because this is a distributed file system...
The project scaffolding built with vue-cli has al...
This article shares with you how to use the Vue c...