我正在构建类似的东西,我选择的国家会自动指定电话国家/地区代码。Vue没有更新依赖于另一个的输入
两个国家和COUNTRYCODE的但是存储在客户对象,当我改变了这个国家的价值,触发正确调用,我可以看到的国家代码Vue的开发工具发生变化,相关的输入不会更新。这是我的代码:
data: function() {
return {
customer: {},
countries: this.$store.state.settings.countries,
}
},
created: function() {
var defaultCountry = _.find(this.countries, { default: true });
this.customer.country = defaultCountry.name;
this.customer.countryCode = defaultCountry.code;
},
methods: {
updateCountryCode: function(country) {
this.customer.countryCode = country.code;
},
}
这是相关的HTML:
<vSelect
label="name"
v-model="customer.country"
:options="countries"
:onChange="updateCountryCode">
</vSelect>
<input type="text" disabled :value="customer.countryCode">
我在做什么错?为什么我会在开发工具中看到更新的数据,但它不会被视为被动,而且我的国家/地区代码输入保持不变?
您应该如此定义您的客户对象 'customer:{country:null,countryCode:null,},' – Nora
什么?这工作!我假设,因为我在创建()时设置了默认值,我不需要在空对象中分配这些值。任何想法为什么这是必要的?此外,请添加此作为一个单独的答案,所以我可以将其标记为已解决:) – Anonymous