【问题标题】:Not able to triger any event on vue-select无法在 vue-select 上触发任何事件
【发布时间】:2019-12-04 09:21:51
【问题描述】:

我正在使用 vue-select 来输入/从下拉列表中选择,所以在选择任何选项时,我试图获取被选中的值

代码

<vueSelect 
       :clearable="false"
       v-on:change="itemCodeChange($event)"
       :options="itemCode">
</vueSelect>

脚本

    import vueSelect from 'vue-select'
    import 'vue-select/dist/vue-select.css';
    components :{
        vueSelect,

    },
  data () {
     return {
        itemCode:[],
     }      
  },
   methods:{
  itemCodeChange (a)
      {
          alert(a)
      }

当我改变时,什么都没有发生

【问题讨论】:

  • 是vueSelect这个东西吗? vue-select.org - 它有 documentation
  • @JaromandaX 主要是更改或输入未触发,我检查了但没有得到它,这就是为什么在这里问
  • @JaromandaX 你能告诉我一些相应的代码吗
  • 将代码中的 v-on:change="itemCodeChange($event)" 更改为 v-on:input="itemCodeChange" - 请注意缺少 $event

标签: javascript vue.js


【解决方案1】:

您需要使用输入事件而不是更改事件:请参阅工作代码

Vue.component('v-select', VueSelect.VueSelect)

new Vue({
  el: '#app',
  data: {
    options: [
      'foo',
      'bar',
      'baz'
    ]
  },
  methods: {
    changed(v) { console.log(v); }
  }
})
@import 'https://fonts.googleapis.com/css?family=Source+Sans+Pro:600';
@import 'https://unpkg.com/vue-select/dist/vue-select.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;
}
<div id="app">
  <h1>Vue Select</h1>
  <v-select :options="options" @input="changed"></v-select>
</div>

<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.min.js"></script>
<script src="https://unpkg.com/vue-select@latest"></script>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-05
    • 2015-11-18
    相关资源
    最近更新 更多