【发布时间】:2021-07-04 20:26:37
【问题描述】:
我正在使用 Vue.js 3,在这里我搜索了数据,但这些数据来自假 API。所以这个搜索只适用于小字符或大字符,但我想搜索大写或小写的抛出数据? 这是我的代码
<template>
<div class='home'>
<h1>Third</h1>
<div v-if="error"> {{error}} </div>
<div v-if="posts.length">
<input type="text" v-model.trim="search" />
<!-- <p>search term - {{search}}</p> -->
<div v-for="post in matchingNames" :key='post.id'>
<h3>{{post.title }}</h3>
<h1>{{post.id}}</h1>
</div>
</div>
<div v-else> Loading...</div>
</div>
</template>
<script>
import { computed, ref, watch, watchEffect} from 'vue'
// import Listing from '../components/Listing.vue'
import getPosts from '../composables/getPosts'
export default {
name:'Third',
components: {} ,
setup(){
const search = ref('')
const{posts,error,load} = getPosts()
load()
const matchingNames = computed (()=> {
return posts.value.filter((post)=>post.title.match(search.value))
})
return {posts, error, search, matchingNames}
}
}
</script>
<style>
</style>
我也试过用includes js方法替换match方法但是结果是一样的
这是现在如何工作的 gif,谁能帮助我我是 Vue.js 3 的新手
【问题讨论】:
标签: javascript api vue.js search match