作为头衔。数据结构是
[ {name: "A city",items:["A district","AB district","ABC district"]}, {name: "B city",items:["B district","BB district","BBC district"]} ]
在选择城市时,区的选择也会发生变化,但不起作用。和默认值:选定也不工作。我怎么解决?我试过用ref代替reactive,但不起作用。谢谢大家。
4c8rllxm1#
试着这样做:
<script setup> import { reactive } from 'vue'; const district = [ {name: "A city",items:["A district","AB district","ABC district"]}, {name: "B city",items:["B district","BB district","BBC district"]} ]; const targetCity = reactive({ city: district[0] }); const targetDistirct = reactive({ district: targetCity.city.items[0] }); const setFirstDistrictAsDefault = () => { targetDistirct.district = targetCity.city.items[0] } </script> <template> <select v-model="targetCity.city" @change="setFirstDistrictAsDefault"> <option v-for="city in district" :value="city" :key="city.name">{{ city.name }}</option> </select> <select v-model="targetDistirct.district"> <option v-for="item in targetCity.city.items" :value="item" :key="item">{{ item }} </option> </select> <p> {{ targetCity.city.name }}<br/> {{ targetDistirct.district }} </p> </template>
1条答案
按热度按时间4c8rllxm1#
试着这样做: