【发布时间】:2021-07-22 02:08:55
【问题描述】:
我目前正在实现一个组件,当 year to / year[1] 值低于 year from / year[ 时更新父级的 year[] 数组0] 与 <b-input>(Bootstrap Vue 库)。
第二次后停止更新的年份。
代码示例如下。
jsfiddle 中的等效代码可以在here 找到。
父.vue
<template>
<child :year="year" @update="update">
</template>
<script>
// Import child component here
export default {
name: 'Parent',
components: {
Child,
},
data: () => ({
year: [100, null],
}),
methods: {
update(newYear) {
this.year = newYear;
},
},
</script>
Child.vue
<template>
<div>
From <b-input :value="year[0]" />
To <b-input :value="year[1]" @change="update" />
</div>
</template>
<script>
export default {
name: 'Child',
props: {
year: {
type: Array,
required: true,
}
},
methods: {
update(yearToVal) {
const [yearFrom] = this.year;
let newYear = [...this.year];
if (yearToVal < yearFrom) {
/* Both of this update end up the same */
// newYear[1] = yearFrom;
this.$set(newYear, 1 , yearFrom);
}
this.$emit('update', newYear);
},
},
};
</script>
我曾使用 Vue Dev Tools 进行检查,孩子正在正确地向父母发送数据。
问题发生在vModalValue 和localValue 上,<b-input> 没有第二次更新。
我做错了什么还是 Bootstrap Vue 库的问题?
【问题讨论】:
标签: vue.js bootstrap-vue