我需要一段vue3的模糊查询代码
时间: 2024-05-08 07:17:52 浏览: 33
以下是Vue3的模糊查询代码:
```
<template>
<div>
<input type="text" v-model="searchTerm" placeholder="Search term..."/>
<ul>
<li v-for="item in filteredItems" :key="item.id">{{ item.name }}</li>
</ul>
</div>
</template>
<script>
import { ref, computed } from 'vue';
export default {
setup() {
const searchTerm = ref('');
const items = [
{id:1, name:'Apple'},
{id:2, name:'Banana'},
{id:3, name:'Cherry'},
{id:4, name:'Durian'},
{id:5, name:'Elderberry'},
];
const filteredItems = computed(() => {
return items.filter(item => {
return item.name.toLowerCase().includes(searchTerm.value.toLowerCase());
});
});
return { searchTerm, filteredItems };
}
};
</script>
```
希望能帮到你。
阅读全文