php - 值没有进入vue js的下拉框中
问题描述
我从数据库获取值到下拉框所在的页面,但下拉框没有返回值。代码如下图,
脚本
methods: {
editState(id){
axios.defaults.headers.common['Authorization'] = "Bearer "+localStorage.getItem('token');
axios.get(baseUrl+'/state/edit/'+id)
.then((response) => {
alert(response.data[0].form.country_name);
this.form = response.data[0].form;
setTimeout(() => {
this.subComponentLoading = true;
}, 500);
})
.catch(function (error) {
console.log(error);
});
}
}
Vue
<d-field-group class="field-group field-row" label-for = "country_name" label="Country Name" label-class="col-4">
<d-select :options="Countries" v-model="form.country_id" id="country_id" name = "country_name" wrapper-class="col-7">
</d-select>
</d-field-group>
解决方案
我看到的两件事是错误的......
Countries
位于form
对象内部,但您没有从那里分配或读取它。将其移至顶层您正在绑定 a
v-model
,form.country_id
但这最初并不存在。将其添加到form
对象。
总结...
data () {
return {
isStateEditVisible: false,
form: {
state_name: '',
isStateEnabled: true,
ISO_Code: '',
country_id: '', // added this
country_name: '',
zone_name: ''
},
Countries: [], // moved this
Zones: [] // and this
}
}
为了对数据变化做出反应,Vue 需要预先了解它们。见https://vuejs.org/v2/guide/reactivity.html
推荐阅读
- c++ - 是否可以在不使用动态调度的情况下创建接口?
- mysql - 如何使用 bash shell 脚本执行 inodbcluster 状态
- java - Spring用额外的列反序列化manytomany表
- salesforce - 在自定义对象中插入操作时自动在 Salesforce 中生成文档
- php - php soap 不会创建客户端?
- c# - 查询字符串 oData 过滤器使用大于运算符
- python - 为什么 random.shuffle() 改变指向变量?
- c# - 在 ASP.NET Core 中使用 firebase 发送通知
- android - Android 领域数据随机丢失/损坏
- bash - 在 bash 命令中为每个 pod 删除添加睡眠时间