简体   繁体   English

如何使用 Vue.js 设置两个依赖项下拉列表

[英]how to setup two dependency dropdown list using Vue.js

I create on dropdown list using Vue.js its running well, but i need to add another list like that, how to setup that, here I add both codes my first code我使用 Vue.js 在下拉列表中创建它运行良好,但我需要添加另一个类似的列表,如何设置,在这里我添加两个代码我的第一个代码

 var addUserVue = new Vue({ el: "#app", data: { heading: "Vue Select Cascade", brand: null, model: null, brands_options: [ { text: "Honda",id: 'Honda' }, { text: "Toyota",id: 'Toyota' }, { text: "Nissan",id: 'Nissan' }, { text: "Suzuki",id: 'Suzuki' } ], model_options: { 'Honda': [ { text: "Accord", id: 'Accord' }, { text: "Civic", id: 'Civic' } ], 'Toyota': [ { text: "Corolla", id: 'Corolla' }, { text: "HiAce", id: 'HiAce' } ], 'Nissan': [ { text: "Altima", id: 'Altima' }, { text: "Zuke", id: 'Zuke' } ], 'Suzuki': [ { text: "Alto", id: 'Alto' }, { text: "Swift", id: 'Suzuki' } ] } } });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script> <div class="col-xs-6" id="app"> <div class="form-group"> <label for="brand">Brand</label> <select class="form-control" name="brand" id="brand" v-model="brand"> <option:value="null" disabled selected>Select Brand</option> <option v-for="option in brands_options" v-bind:value="option.id" >{{ option.text}}</option> </select> </div> <div class="form-group"> <label for="model">Model</label> <select class="form-control" name="model" id="model" v-model="model"> <option:value="null" disabled selected>Select Model</option> <option v-for="option in model_options[brand]" v-bind:value="option.id" v-bind:key="option.id">{{option.text}}</option> </select> </div> </div>

this code is running well, but this page is fail to load when I add js file, I think trouble in the second js file, help me to solve that这段代码运行良好,但是当我添加 js 文件时,这个页面无法加载,我认为第二个 js 文件有问题,帮我解决这个问题

second code here第二个代码在这里

 var location = new Vue({ el: "#location", data: { heading: "Vue Select Cascade", District: null, City: null, Districts_options: [ { text: "Rathnapura",id: 'Rathnapura' }, { text: "Kegalle",id: 'Kegalle' }, { text: "Colombo",id: 'Colombo' }, { text: "Gampaha",id: 'Gampaha' } ], City_options: { 'Rathnapura': [ { text: "Eheliyagoda", id: 'Eheliyagoda' }, { text: "Kuruwita", id: 'Kuruwita' } ], 'Kegalle': [ { text: "Mawanella", id: 'Mawanella' }, { text: "Kegalle", id: 'Kegalle' } ], 'Colombo': [ { text: "Awissawella", id: 'Awissawella' }, { text: "Homagama", id: 'Homagama' } ], 'Gampaha': [ { text: "Gampaha", id: 'Gampaha' }, { text: "Minuwangoda", id: 'Minuwangoda' } ] } } });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script> <div class="col-xs-6" id="location"> <div class="form-group"> <label for="District">Select District</label> <select class="form-control" name="District" id="District" v-model="District"> <option:value="null" disabled selected>Select District</option> <option v-for="option in Districts_options" v-bind:value="option.id" >{{ option.text}}</option> </select> </div> <div class="form-group"> <label for="City">City</label> <select class="form-control" name="City" id="City" v-model="City"> <option:value="null" disabled selected>Select City</option> <option v-for="option in City_options[District]" v-bind:value="option.id" v-bind:key="option.id">{{option.text}}</option> </select> </div> </div>

location refers to the window property window.location and therefore should be avoided . location指的是 window 属性window.location ,因此应避免使用

If you change var location = new Vue({ to something else,如果您将var location = new Vue({更改为其他内容,

eg var l = new Vue({ , your code works.例如var l = new Vue({ ,您的代码有效。

 var l = new Vue({ el: "#location", data: { heading: "Vue Select Cascade", District: null, City: null, Districts_options: [ { text: "Rathnapura",id: 'Rathnapura' }, { text: "Kegalle",id: 'Kegalle' }, { text: "Colombo",id: 'Colombo' }, { text: "Gampaha",id: 'Gampaha' } ], City_options: { 'Rathnapura': [ { text: "Eheliyagoda", id: 'Eheliyagoda' }, { text: "Kuruwita", id: 'Kuruwita' } ], 'Kegalle': [ { text: "Mawanella", id: 'Mawanella' }, { text: "Kegalle", id: 'Kegalle' } ], 'Colombo': [ { text: "Awissawella", id: 'Awissawella' }, { text: "Homagama", id: 'Homagama' } ], 'Gampaha': [ { text: "Gampaha", id: 'Gampaha' }, { text: "Minuwangoda", id: 'Minuwangoda' } ] } } });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script> <div class="col-xs-6" id="location"> <div class="form-group"> <label for="District">Select District</label> <select class="form-control" name="District" id="District" v-model="District"> <option:value="null" disabled selected>Select District</option> <option v-for="option in Districts_options" v-bind:value="option.id" >{{ option.text}}</option> </select> </div> <div class="form-group"> <label for="City">City</label> <select class="form-control" name="City" id="City" v-model="City"> <option:value="null" disabled selected>Select City</option> <option v-for="option in City_options[District]" v-bind:value="option.id" v-bind:key="option.id">{{option.text}}</option> </select> </div> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM