在vue.js中使用空白空间搜索问题

发布于 2025-02-01 04:13:10 字数 1003 浏览 0 评论 0原文

我在vue.js中的输入搜索字段有问题。

在我的数据中,我有嵌套阵列,它们具有标题。当我搜索标题并击中空间时,什么也不会出现。并应使用空格搜索标题。例如,我有一个标题为“商店中的铅笔”,当我在输入中写“铅笔”时,它确实与所有其他信息一起出现。当我写“铅笔”时,什么都没有出现。另外,在某些标题中,我无法到达空白空间,只有在写“笔”时才会出现结果。这是我的代码,我尝试了修剪和分裂,但它没有用。 非常感谢!

computed: {
getfiltered() {
    const search = this.search;
    return (
    this.categories.filter(category =>
    category.title.includes(search.toLowerCase()) ||
    category.infos.some(info => info.name.includes(search)
    )
  )
)
},

这是输入字段

<input type="text" v-model="search" placeholder="Search" />
   <div v-for="(category, categoryIndex) in getfiltered" :key="categoryIndex">
     <h2>{{category.title}}</h2>
   </div>

和数据

export default {
  data: () => ({
    search: '',
      categories: [
         {
           title: 'Pencils in store',
           infos: [{name:'Bic'},
                   {name:'Crayola'}]
          }, //...and so on

I have a problem with input search field in vue.js.

In my data I have nested arrays, which have titles. When I search the titles and hit space, nothing appears. And titles should be searched with spaces. For example I have a title "Pencils in store" and when I write "Pencils" in input, it does appear with all other information. When I write "Pencils in" nothing appears. Also, in some of the titles I can't reach to the blank space, results appears only while I write "Pen". Here is my code, I have tried with trim and split, but it did not work.
Very thanks in advance!

computed: {
getfiltered() {
    const search = this.search;
    return (
    this.categories.filter(category =>
    category.title.includes(search.toLowerCase()) ||
    category.infos.some(info => info.name.includes(search)
    )
  )
)
},

Here is the input field

<input type="text" v-model="search" placeholder="Search" />
   <div v-for="(category, categoryIndex) in getfiltered" :key="categoryIndex">
     <h2>{{category.title}}</h2>
   </div>

And the data

export default {
  data: () => ({
    search: '',
      categories: [
         {
           title: 'Pencils in store',
           infos: [{name:'Bic'},
                   {name:'Crayola'}]
          }, //...and so on

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

楠木可依 2025-02-08 04:13:10

@estus烧瓶评论的方式解决了问题。
category.title.tolowercase()。包括(search.tolowercase())

The problem is solved in a way that @Estus Flask commented.
сategory.title.toLowerCase().includes(search.toLowerCase())

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文