vue elementui二级联动下拉选项demo
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<!-- 引入样式 -->
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<!-- 引入组件库 -->
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<title>Document</title>
</head>
<body>
<div id="app">
<el-select v-model="province" placeholder="请选择" @change="selectChange">
<el-option v-for="item in compony" :key="item.code" :label="item.name" :value="item.code">
</el-option>
</el-select>
<el-select v-model="city" placeholder="请选择">
<el-option v-for="item in newCity" :key="item.code" :label="item.name" :value="item.code">
</el-option>
</el-select>
</div>
<script>
let vm = new Vue({
el: '#app',
data() {
return {
province:"",
city:"",
newCity:[],
compony: [{
"code": 1,
"name": '区域1',
"childrens": [{
"code": 01,
"name": '广东'
},{
"code": 02,
"name": '江西'
}],
},
{
"code": 2,
"name": '区域2',
"childrens": [{
"code": 03,
"name": '北京'
},{
"code": 04,
"name": '东'
}
],
}]
}
},
methods: {
selectChange(value){
console.log(value);
this.newCity = this.compony[value-1].childrens
this.city = this.newCity[0].name
console.log(this.newCity[0],'newcity')
}
}
})
</script>
</body>
</html>