使用VUEJS的Quasar Multi Select值组件

发布于 2025-02-12 02:59:15 字数 2666 浏览 0 评论 0原文

我在项目中使用Vuejs和Quasar,我正在尝试进行自动完成选择以选择一些值,当用户试图键入一些文本时,将API发送到服务器以检索。所有值都包含文本,这是代码:

<template>

<div class="autocomplete">

<q-select

  filled

  label="Search"

  v-model="searchTerm"

  use-input

  use-chips

  multiple

  @filter="filterFn"

  @input-value="inputValue"

  @filter-abort="abortFilterFn"

  :options="searchResult"

  style="width: 395px"

  :option-label=""

    option-value="text"

   >

   <template v-slot:no-option>

    <q-item>

      <q-item-section class="text-grey"> No results </q-item-section>

    </q-item>

  </template>

</q-select>

<div>

  <back-button @click="go" data-test="btn-back" forwardicon="arrowright" />

</div>
<script>

import { defineComponent, ref, computed } from "vue";

import { apiProductService } from "../../models/";

import apiEndPoints from "../../models/api";

import BackButton from "../ui/";

 import { useRouter } from "vue-router";

 import { useSearchStore } from "../../store/";

 import _ from "lodash";

 import { debounce } from "quasar";

export default defineComponent({

  name: "search-bar",

components: { BackButton },



setup(props, context) {

const router = useRouter();

let searchTerm = ref(null);

let searchResult = ref([]);

const search = useSearchStore();



function filterFn(val, update, abort) {

  if (searchResult.value.length > 0) {

    update();

    return;

  }



  

  abortFilterFn();

   document.addEventListener('keypress', function(e) {

    
          true

        });

}

function abortFilterFn() {

  // console.log('delayed filter aborted')

}



const inputValue = computed(() => debounce(suggestions, 0).bind(this));



function suggestions(val) {

  if (val) {

    getSearchData(val);

    document.addEventListener('keypress', function(e) {

   true

  });

  } else {

    searchResult.value = [];

  }

}



const getSearchData = async (val) => {

  await apiProductService(

    apiEndPoints.GetSearchSuggestions.method,

    apiEndPoints.GetSearchSuggestions.url,

    {

      q: val,

      top: 5,

      suggester: "sg",

    }

  ).then((response) => {

    searchResult.value = response?.data?.suggestions || [];

  });

};



}

return {

  searchTerm,

  searchResult,

  filterFn,

  inputValue

  
  };

},

});

代码的问题是当我尝试键入例如术语“ tes”时,我可以看到DB检索到的数据,当我对所需的值(类型text Text)在多选组件上使用:

”在此处输入图像说明“

我如何删除类型文本?

I'm using Vuejs and Quasar on my project, I'm trying to do an autocomplete select to select some value, when the user tries to type some text, an API is sent to the server to retrieve. all the values contains that text, heres the code :

<template>

<div class="autocomplete">

<q-select

  filled

  label="Search"

  v-model="searchTerm"

  use-input

  use-chips

  multiple

  @filter="filterFn"

  @input-value="inputValue"

  @filter-abort="abortFilterFn"

  :options="searchResult"

  style="width: 395px"

  :option-label=""

    option-value="text"

   >

   <template v-slot:no-option>

    <q-item>

      <q-item-section class="text-grey"> No results </q-item-section>

    </q-item>

  </template>

</q-select>

<div>

  <back-button @click="go" data-test="btn-back" forwardicon="arrowright" />

</div>
<script>

import { defineComponent, ref, computed } from "vue";

import { apiProductService } from "../../models/";

import apiEndPoints from "../../models/api";

import BackButton from "../ui/";

 import { useRouter } from "vue-router";

 import { useSearchStore } from "../../store/";

 import _ from "lodash";

 import { debounce } from "quasar";

export default defineComponent({

  name: "search-bar",

components: { BackButton },



setup(props, context) {

const router = useRouter();

let searchTerm = ref(null);

let searchResult = ref([]);

const search = useSearchStore();



function filterFn(val, update, abort) {

  if (searchResult.value.length > 0) {

    update();

    return;

  }



  

  abortFilterFn();

   document.addEventListener('keypress', function(e) {

    
          true

        });

}

function abortFilterFn() {

  // console.log('delayed filter aborted')

}



const inputValue = computed(() => debounce(suggestions, 0).bind(this));



function suggestions(val) {

  if (val) {

    getSearchData(val);

    document.addEventListener('keypress', function(e) {

   true

  });

  } else {

    searchResult.value = [];

  }

}



const getSearchData = async (val) => {

  await apiProductService(

    apiEndPoints.GetSearchSuggestions.method,

    apiEndPoints.GetSearchSuggestions.url,

    {

      q: val,

      top: 5,

      suggester: "sg",

    }

  ).then((response) => {

    searchResult.value = response?.data?.suggestions || [];

  });

};



}

return {

  searchTerm,

  searchResult,

  filterFn,

  inputValue

  
  };

},

});

the problem with code is when I try to type for example the term "tes", I can see the data retrieved for the db, when I clic on the desired value, the type text is savec on the multi selected component like:

enter image description here

how can I remove the type text please ?

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

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

发布评论

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

评论(1

倾城泪 2025-02-19 02:59:15

使用ref and updateInputValue进行清除输入。

https://codepen.io/pratik__007/pen

Use ref and use updateInputValue for clear input.

https://codepen.io/Pratik__007/pen/RwMWbwK

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