我有一个数据表列表,我想搜索客户名称。客户名称是从客户表(关系)中获取的。我在代码上尝试了更多时间,但是没有处理。很抱歉,因为我是Vue js的新手。
文本域
<div>
<v-text-field
label="Search Customer"
solo
outlined
dense
v-model="search"
></v-text-field>
</div>
脚本
<script>
export default {
created() {
this.fetchSearch();
},
watch: {
search: {
handler() {
this.fetchSearch()
}
},
deep: true,
},
data() {
return {
items: [],
search: '',
}
},
methods: {
fetchSearch(){
this.$axios.$get(`/api/return-sale?search=${this.search}`)
.then(res =>{
this.items = res.returnsale.data;
console.log(res);
})
.catch(err =>{
console.log(err.response);
})
},
}
}
</script>
您可以通过watch属性为this.items创建一个函数并过滤数据
watch: {
search() {
const data = this.items
if (this.search.length > 0) {
if (data.filter(item => item.custormerName === this.search)) {
this.items = data.filter(item => item.custormerName === this.search);
} else {
this.search = '';
this.fetchSearch();
}
} else {
this.fetchSearch();
}
}
}
只需添加手表即可。不行
乐意效劳...