<template>
<v-form :model='agency'>
<v-layout row wrap>
<v-flex xs12 sm12 lg12 >
<v-layout row wrap>
<v-flex xs12 md12 class="add-col-padding-right">
<v-radio-group
v-model="agency.location"
:mandatory="true"
label="Please select one of the options below">
<v-radio label="NYC" value="nyc"></v-radio>
<v-radio label="SAN JOSE" value="san_jose"></v-radio>
</v-radio-group>
</v-flex>
</v-layout>
</v-flex>
</v-layout>
</v-form>
</template>
<script>
export default {
data: function () {
return {
agency: {
id: '',
name: '',
location: '',
contacts: {
name: '',
number: '',
address: ''
}
},
final_location_contact: {
name: '',
number: '',
address: ''
}
}
}
watch: {
agency: {
handler(val){
if (this.agency.location === "nyc") {
this.final_location_contact = this.agency.contacts;
}
}
},
created: function() {
this.fetchAgency();
},
method: {
fetchAgency() {
this.$axios.get('/agency.json')
.then(response => {
if (Object.keys(response.data).length > 0) {
this.agency = response.data;
}
}).
then(() => {
});
},
}
}
</script>
我在这里面临的问题是页面加载时,并且 fetchAgency 方法运行并且我能够获取代理数据。当我从单选按钮中选择第一个选项时,我可以将值 agent.contacts 值分配给 final_location_contact。但是当我第一次选择 San Jose 单选按钮选项,然后我选择 nyc 单选按钮然后我无法将值 agent.contacts 值分配给 final_location_contact 时,问题就出现了,因为我使用调试器检查了 agent.contacts 的值是空的. 但如果我第一次选择 nyc,它不会为空。任何想法可能是问题所在?
'agency.location': {
handler (newValue, oldValue) {
if (newValue === "nyc") {
this.final_location_contact = this.agency.contacts;
}
else {
this.final_location_contact.name: '',
this.final_location_contact.number: '',
this.final_location_contact.address: ''
}
}
}