我想将三个下拉框变成一个组件 初始是没问题的 下拉福州市可以读取接口获取福州市的几个区 然后选区 查到街道 但是直接传值的时候一次性把三个都传进去导致第一个读取了 后面两个被重置了 一个一个传又破坏了组件整体性该怎么办js代码如下
`<template>
<div>
<el-select v-model="value.citycode" class="first-select" placeholder="请选择市级">
<el-option v-for="item in citycodeDict" :key="item.id" :label="item.name" :value="item.code"></el-option>
</el-select>
<el-select v-model="value.countrycode" placeholder="请先选择市级">
<el-option v-for="item in countrycodeDict" :key="item.id" :label="item.name" :value="item.code"></el-option>
</el-select>
<el-select v-model="value.towncode" placeholder="请先选择区/县级">
<el-option v-for="item in towncodeDict" :key="item.id" :label="item.name" :value="item.code"></el-option>
</el-select>
</div>
</template>
<script>
export default {
name: 'AreaSelect',
model: {
prop: 'value',
event: 'change',
},
props: {
value: Object,
},
data () {
return {
citycodeDict: [{
name: '全部',
code: '',
}],
countrycodeDict: [{
name: '全部',
code: '',
}],
towncodeDict: [{
name: '全部',
code: '',
}],
}
},
watch: {
'value.citycode': {
handler: function (nVal) {
if (!nVal) {
this.reset('countrycodeDict', 'countrycode')
this.reset('towncodeDict', 'towncode')
} else {
const id = this.citycodeDict.find(e => e.code === nVal).id
this.init(id, 'countrycodeDict')
this.value.countrycode = ''
this.value.towncode = ''
}
},
},
'value.countrycode': {
handler: function (nVal) {
if (!nVal) {
this.reset('towncodeDict', 'towncode')
} else {
const id = this.countrycodeDict.find(e => e.code === nVal).id
this.init(id, 'towncodeDict')
this.value.towncode = ''
}
},
},
},
created () {
this.init(1, 'citycodeDict')
},
methods: {
init (id, target) {
const data = {
parentId: id || 1,
}
// 获取列表
const _this = this
this.$http({
url: _this.$http.adornUrl('aa/bb/cc'),
method: 'get',
params: data,
}).then(({ data }) => {
if (data && data.code === 200) {
this[target] = [{ name: '全部', code: '' }]
this[target] = this[target].concat(data.data)
}
})
},
reset (valueDict, value) {
this[valueDict] = [
{
name: '全部',
code: '',
},
]
this.value[value] = ''
},
},
}
</script>
<style scoped>
</style>`
试试这个方案