v-on:keyup not firing功能

时间:2018-04-22 01:10:54

标签: vuejs2

出于某种原因,我无法触发我的keyup事件。我希望它能听到任何和所有的键盘事件,因为我正在尝试制作实时搜索功能

这是我的代码:

<template>
...
<b-form-input id="search"
              v-model="query"
              type="text"
              placeholder="Search"
              v-on:keyup="find(search, query)">
</b-form-input>

....

</template>

<script type="text/javascript">
export default {
data() {
  return {
    options: [
        { text: 'All', value: 'All' },
        { text: 'Members', value: 'Members' },
        { text: 'Groups', value: 'Groups' },
        { text: 'Events', value: 'Events' }
    ],
    search: 'All',
    query: '',
    results: []
  }
},

methods: {
    find: function (param = 'All', string = '') {
        axios.get('/api/search/' + param.toLowerCase() + '?query=' + string)
    .then(({data}) => {
        this.results = data.data;
    });
    }
}}
</script>

我只能做v-on:改变让它开火。

1 个答案:

答案 0 :(得分:4)

b-form-input仅支持inputchange事件。

要使用keyup事件侦听器,请向其添加.native

@keyup.native="..."

来自https://bootstrap-vue.js.org/docs/components/form-input#component-reference

enter image description here