1 <template> 2 <div> 3 <!-- 省 --> 4 <select v-model="provinceid" @change="updatCity()"> 5 <option v-for="(item,index) in provinceArr" :value="item.name" :key="index" >{{item.name}}</option> 6 </select> 7 {{provinceid}} 8 <!-- 市 --> 9 <select v-model="shi" @change="updatShi()"> 10 <option v-for="(item,index) in shiArr" :key="index" :value="item.name" >{{item.name}}</option> 11 </select> 12 {{shi}} 13 <select v-model="qu" > 14 <option v-for="(item,index) in quArr" :key="index" :value="item">{{item}}</option> 15 </select> 16 {{qu}} 17 </div> 18 </template> 19 20 <script> 21 export default{ 22 data(){ 23 return{ 24 // 數據 25 // 存放默認市的 26 provinceid:'北京市', 27 provinceArr:[{ 28 name: "北京市", 29 city: [{ 30 name: "北京市", 31 districtAndCounty: ["東城區", "西城區", "崇文區", "宣武區", "朝陽區", "豐台區", "石景山區", "海淀區", "門頭溝區", "房山區", "通州區", "順義區", "昌平區", "大興區", "懷柔區", "平谷區", "密雲縣", "延慶縣", "延慶鎮"] 32 }] 33 }, { 34 name: "重慶市", 35 city: [{ 36 name: "重慶市", 37 districtAndCounty: ["渝中區", "大渡口區", "江北區", "沙坪壩區", "九龍坡區", "南岸區", "北碚區", "萬盛區", "雙橋區", "渝北區", "巴南區", "萬州區", "涪陵區", "黔江區", "長壽區", "合川市", "永川區市", "江津市", "南川市", "綦江縣", "潼南縣", "銅梁縣", "大足縣", "榮昌縣", "璧山縣", "墊江縣", "武隆縣", "豐都縣", "城口縣", "梁平縣", "開縣", "巫溪縣", "巫山縣", "奉節縣", "雲陽縣", "忠縣", "石柱土家族自治縣", "彭水苗族土家族自治縣", "酉陽土家族苗族自治縣", "秀山土家族苗族自治縣"] 38 }] 39 }, { 40 name: "河北省", 41 city: [{ 42 name: "石家庄市", 43 districtAndCounty: ["長安區", "橋東區", "橋西區", "新華區", "裕華區", "井陘礦區", "辛集市", "藁城市", "晉州市", "新樂市", "鹿泉市", "井陘縣", "微水鎮", "正定縣", "正定鎮", "欒城縣", "欒城鎮", "行唐縣", "龍州鎮", "靈壽縣", "靈壽鎮", "高邑縣", "高邑鎮", "深澤縣", "深澤鎮", "贊皇縣", "贊皇鎮", "無極縣", "無極鎮", "平山縣", "平山鎮", "元氏縣", "槐陽鎮", "趙縣", "趙州鎮"] 44 }, { 45 name: "張家口市", 46 districtAndCounty: ["橋西區", "橋東區", "宣化區", "下花園區", "宣化縣", "張家口市宣化區", "張北縣", "張北鎮", "康保縣", "康保鎮", "沽源縣", "平定堡鎮", "尚義縣", "南壕塹鎮", "蔚縣", "蔚州鎮", "陽原縣", "西城鎮", "懷安縣", "柴溝堡鎮", "萬全縣", "孔家庄鎮", "懷來縣", "沙城鎮", "涿鹿縣", "涿鹿鎮", "赤城縣", "赤城鎮", "崇禮縣", "西灣子鎮"] 47 }, { 48 name: "承德市", 49 districtAndCounty: ["雙橋區", "雙灤區", "鷹手營子礦區", "承德縣", "下板城鎮", "興隆縣", "興隆鎮", "平泉縣", "平泉鎮", "灤平縣", "灤平鎮", "隆化縣", "隆化鎮", "豐寧滿族自治縣", "大閣鎮", "寬城滿族自治縣", "寬城鎮", "圍場滿族蒙古族自治縣", "圍場鎮"] 50 }, { 51 name: "秦皇島市", 52 districtAndCounty: ["海港區", "山海關區", "北戴河區", "昌黎縣", "昌黎鎮", "撫寧縣", "撫寧鎮", "盧龍縣", "盧龍鎮", "青龍滿族自治縣", "青龍鎮"] 53 }] 54 55 }], 56 // 存放默認市的 57 shi:"北京市", 58 shiArr:[{name:"北京市"}], 59 // 存放默認區的 60 qu:"東城區", 61 quArr:["東城區"] 62 } 63 }, 64 methods:{ 65 // 方法 切換城市要改變數據 66 updatCity(){ 67 var ref=this; 68 this.provinceArr.forEach(function(item,index){ 69 if(item.name==ref.provinceid){ 70 ref.shiArr=item.city; 71 ref.shi=ref.shiArr[0].name; 72 return; 73 } 74 }) 75 this.shiArr.forEach(function(item,index){ 76 if(item.name==ref.shi){ 77 ref.quArr=item.districtAndCounty; 78 ref.qu=ref.quArr[0]; 79 return; 80 } 81 }) 82 83 }, 84 updatShi(){ 85 var ref=this; 86 this.shiArr.forEach(function(item,index){ 87 if(item.name==ref.shi){ 88 ref.quArr=item.districtAndCounty; 89 ref.qu=ref.quArr[0]; 90 return; 91 } 92 }) 93 } 94 95 } 96 97 } 98 </script> 99 100 <style></style>