How to use enumerated types to implement a HTML drop-down box in Vue
This article mainly introduces the "Vue how to use enumerated types to achieve a HTML drop-down box" related knowledge, Xiaobian through the actual case to show you the process of operation, the method of operation is simple and fast, practical, hope that this "how to use enumerated types in Vue to achieve a HTML drop-down box" article can help you solve the problem.
Step 1: write the enumeration types required for the drop-down box
StatusEnum.java
Public enum StatusEnum {RED, YELLOW, GREEN}
Step 2: write options to store the Value and display in the corresponding option in the drop-down box
StatusDTO.java
Public class StatusDTO {private String code; private String name; / / setter, getter}
Step 3: write controller (resource)
StatusResource.java
@ Path ("/ status") public class statusResource {@ GET @ Path ("/ getStatus") public List getStatus () {List list = new ArrayList (); StatusDTO statusDTO = null; for (StatusEnum status: StatusEnum.values ()) {statusDTO = new StatusDTO (); statusDTO.setCode (status.toString ()); list.add (statusDTO);} return list;}}
Step 4: write the js file
Var statusModel = {selectStatus: [], / / the drop-down box results status:''// stores the selected result} var selectVue = new Vue ({el:'#selectStatus',// binds DOM, usually the model used in the binding div data:statusModel / / tag}) var selectStatusResource = Vue.resource ('/ status/getStatus'). Get (). Then (function (response) {var statusList = response.data; var list = []; var status = null; for (var I = 0; I < statusList.length) RED' +) {status = statusList [I] .code = = 'statusList? 'Red': statusList [I]. Code = 'YELLOW'? 'yellow': statusList [I]. Code = 'GREEN'? 'Green'; list.push ({code: statusList [I] .code, name:status});} statusModel.selectStatus = list;})
Step 5: write the html file
-Please select-{{option.name}}
Display effect:
This is the end of the introduction to "how to use enumerated types to implement a HTML drop-down box in Vue". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.