vue.js - Vuetify 创建 2 个相关的 v-select
问题描述
有什么方法可以改变 Alist v-select,基于 Alist 项目到 ajax,并将结果应用于 Blist 项目循环?这就是我为整合所做的。但它显示:Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value. Prop being mutated: "items"
<tr v-for="(item, index) in list" :key="index">
<td>
<v-select style="width: 250px" :items="Alist" label="Purchase Order" @change="updateBlist(index, $event)"></v-select>
</td>
<td>
<v-select style="width: 250px" :ref="'Blist'+index" :items="Blist" label="Group Tasks"></v-select>
</td>
</tr>
<script>
export default {
data() {
Blist: [],
Alist: [],
},
methods: {
updateBlist(index, value) {
// Get Group Task List
axios
.get("/api/Blist/list/" + value)
.then((resp) => {
this.$refs.[`Blist${index}`][0].items = [];
_.forEach(resp.data.data, (value, key) => {
var tmp = {
text: value.name,
value: value.uuid,
};
this.$refs.[`Blist${index}`][0].items.push(tmp);
});
});
}
}
}
</script>
解决方案
将您的 Alist 选择和 Blist 选择放在子组件中,这样您就不必处理数组索引。如果你想要 Blist 在父组件中的值,只需发出它。
就像是:
子组件
<template>
<td>
<v-select style="width: 250px" :items="Alist" label="Purchase Order" @change="updateBlist"></v-select>
</td>
<td>
<v-select style="width: 250px" :items="Blist" label="Group Tasks"></v-select>
</td>
</template>
<script>
export default {
data() {
Blist: [],
Alist: [],
},
methods: {
updateBlist(value) {
// Get Group Task List
axios
.get("/api/Blist/list/" + value)
.then((resp) => {
this.Blist = resp.data.data.map(value=>({
text: value.name,
value: value.uuid,
}))
});
}
}
}
</script>
父组件
<tr v-for="(item, index) in list" :key="index">
<ChildComponent />
</tr>
推荐阅读
- c++ - 如何使用 glut openGL 绘制 4 角星
- c++ - 在 ros noetic 中与 pcl_ros 一起使用时 cv::viz::Viz3d 崩溃
- python - Pandas 错误:“IndexError:iloc 无法放大其目标对象”
- excel - 静默 VBA 添加新的 Excel 工作表而无需屏幕更新
- sql - 根据日期范围内是否(完全)包含年份进行匹配
- java - Jackson 使用 + 和 t 字符反序列化日期字符串
- c++ - operator<=> 应该合成数组比较吗?
- python - 将页眉和页脚添加到 Python 的 JSON 输出
- android - 我无法在 Android 10 中使用 DownloadManger 下载文件?
- html - 页面缩小时试图让导航栏消失