Skip to content
Advertisement

How to create dynamic two relational dropdown in Vuejs

I am new to . I’m stuck trying to dynamically set the options of one select based on the selected value in another.

For example, I have two dropdowns named division and district.

JavaScript

If value of A is 1, then the district select should load the related codes. I can do it with jQuery but not with Vue.

Here is my template.

JavaScript

Here is my javascript.

JavaScript

How can I load the dist_code select with related data from ajax when div_code value is 1?

Advertisement

Answer

Handle a change event on the div_code change

JavaScript

And add the onDivCodeChange method to your Vue.

JavaScript

And of course add code_list as a property of your data and update your template.

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement