forked from tansuo1989/vue-component
-
Notifications
You must be signed in to change notification settings - Fork 0
/
area.vue
83 lines (76 loc) · 1.81 KB
/
area.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<template>
<div class="container">
<div class="row">
<div class="col">
<select v-model="f.p" @change="selpro">
<option :value="i" v-for="(v,i) in pro" :key="v.id">{{v.name}}</option>
</select>
</div>
<div class="col">
<select v-model="f.c" @change="selcity">
<option :value="i" v-for="(v,i) in city" :key="v.id">{{v.name}}</option>
</select>
</div>
<div class="col">
<select v-model="f.cc" v-show="county.length>0" @change="result">
<option :value="i" v-for="(v,i) in county" :key="v.id">{{v.name}}</option>
</select>
</div>
</div>
</div>
</template>
<style scoped>
.row{display: flex;}
.col{flex-grow:1;}
select{width:96%;padding:.5rem;border:1px solid #eee;margin:2%;border-radius: .3rem;font-size: 1.2rem;}
</style>
<script>
import data from "./data";
export default {
data:function(){
return {
data:data,
pro:"",
city:"",
county:"",
f:{
p:0,
c:0,
cc:0,
}
}
},
created:function(){
this.pro=this.data;
this.city=this.pro[0]['child'];
this.county=this.city[0]['child'];
this.result();
},
methods:{
selpro:function(){
this.city=this.pro[this.f.p]['child'];
this.county=this.city[0]['child'];
this.f.c=0;
this.f.cc=0;
this.result();
},
selcity:function(){
this.county=this.city[this.f.c]['child']?this.city[this.f.c]['child']:[];
this.f.cc=0;
this.result();
},
result:function(){
var re={
pro:{id:this.pro[this.f.p].id,name:this.pro[this.f.p].name},
city:{id:this.city[this.f.c].id,name:this.city[this.f.c].name},
};
if(this.county.length>0){
re.county={id:this.county[this.f.cc].id,name:this.county[this.f.cc].name};
}else{
re.county={id:"",name:""};
}
this.$emit("select",re);
}
}
}
</script>