单击带有空选项的 vue select 时,如何处理挂起的选项“抱歉,没有匹配的选项”?

ren*_*qot 2 vue.js

我使用 vue-select 创建选择选项。但是,我对 vue-select 为空时的行为有疑问,它显示消息“抱歉,没有选项匹配”。

HTML 代码:

<div id="app">
  <h1>Vue Select - Custom Labels</h1>
  <v-select label="countryName" :options="options"></v-select>
</div>
Run Code Online (Sandbox Code Playgroud)

CSS代码:

body {
    font-family: 'Source Sans Pro', 'Helvetica Neue', Arial, sans-serif;
}

h1 {
  font-size: 26px;
  font-weight: 600;
  color: #2c3e5099;
  text-rendering: optimizelegibility;
  -moz-osx-font-smoothing: grayscale;
  -moz-text-size-adjust: none;
}

#app {
  max-width: 30em;
  margin: 1em auto;
}
Run Code Online (Sandbox Code Playgroud)

JS代码:

Vue.component("v-select", VueSelect.VueSelect);

new Vue({
  el: "#app",
  data: {
    options: null
  }
});
Run Code Online (Sandbox Code Playgroud)

https://codepen.io/sagalbot/pen/aEjLPB

制作一个数据,选项:null

下拉菜单将显示消息“抱歉,没有匹配的选项”。单击该选项,下拉选择将挂起。

我预计 dropdwon 选择会在选择“抱歉,没有匹配的选项”时关闭。

lju*_*adr 5

vue-select允许插槽,我在这个codepen中找到了插槽列表

因此,您可以使用未找到选项的插槽,并在单击该元素时使用ref和关闭选择$refsv-select我在这个github 问题中找到了有关如何关闭的更多信息

<v-select ref="select">
  <span slot="no-options" @click="$refs.select.open = false">
    Sorry, no matching options
  </span>
</v-select>
Run Code Online (Sandbox Code Playgroud)