In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
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.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.