vue.js - (在 nuxt js 中进行 vuetify)自动完成不是相对于 items 属性的更新
问题描述
搜索中的每个输入我都会更新 items 道具,但 v-autocomplete 变为空,尽管我的组件中的数据发生了变化我尝试添加无过滤器道具它没有帮助我猜测反应性被破坏的东西我也尝试使用计算属性作为项目,但结果仍然相同
搜索中的每个输入我都会更新 items 道具,但 v-autocomplete 变为空,尽管我的组件中的数据发生了变化我尝试添加无过滤器道具它没有帮助我猜测反应性被破坏的东西我也尝试使用计算属性作为项目,但结果仍然相同
<script>
import ProductCartCard from "~/components/cart/ProductCartCard";
export default {
name: "search-app",
components: {
ProductCartCard
},
props: {
items: {
type: Array,
default: () => []
}
},
data() {
return {
loading: false,
filteredItems: [],
search: null,
select: null
};
},
watch: {
search(val) {
if (!val || val.length == 0) {
this.filteredItems.splice(0, this.filteredItems.length);
return;
} else {
val !== this.select && this.querySelections(val);
}
}
},
methods: {
querySelections(v) {
this.loading = true;
// Simulated ajax query
setTimeout(() => {
this.filteredItems.splice(
0,
this.filteredItems.length,
...this.items.filter(i => {
return (i.externalName || "").toLowerCase().includes((v || "").toLowerCase());
})
);
this.loading = false;
}, 500);
}
}
};
</script>
<template>
<div class="search-app-container">
<v-autocomplete
v-model="select"
:loading="loading"
:items="filteredItems"
:search-input.sync="search"
cache-items
flat
hide-no-data
hide-details
label="searchProduct"
prepend-icon="mdi-database-search"
solo-inverted
>
<template v-slot:item="data">
<ProductCartCard :regularProduct="data" />
</template>
</v-autocomplete>
</div>
</template>
解决方案
v-autocomplete
如文档中所述的警告之一:
当为 items 属性使用对象时,您必须将 item-text 和 item-value 与对象上的现有属性相关联。这些值默认为 text 和 value 并且可以更改。
这可能会解决您的问题
推荐阅读
- r - 寻找解释变量的方差膨胀因子
- authentication - 如何使用 jwt 令牌和 auth0 验证 nextjs api 方法
- flutter - Initstate 方法不初始化控制器
- javascript - 使用 Jmeter 设置规则自定义 JSR223 断言和验证响应
- python - 从文本框小部件评估表达式时的 Pyplot 警告
- sql - 处理变量/参数的输入空值
- ios - 如何在 AVPlayer 中嵌入 CollectionViewCell?
- android - 在 React Native 中使用日期选择器阻止特定日期
- wordpress - 将 CSS 库集成到 WordPress 中的最简单方法是什么
- datatables-1.10 - JQuery Datatables Export 导致页面大小不显示