Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vue.js 无法使用keydown事件更新输入值_Vue.js_Jestjs - Fatal编程技术网

Vue.js 无法使用keydown事件更新输入值

Vue.js 无法使用keydown事件更新输入值,vue.js,jestjs,Vue.js,Jestjs,我正在编写一个测试用例,需要使用keydown事件更新输入值,但无法更改输入值。请帮忙 下面是我尝试过的代码,但它不起作用 import { Component } from 'vue'; import Vuex from 'vuex'; import { createLocalVue, shallowMount } from '@vue/test-utils'; import numericOnly from '@/directives/input-numeric-only'; const

我正在编写一个测试用例,需要使用
keydown
事件更新输入值,但无法更改输入值。请帮忙

下面是我尝试过的代码,但它不起作用

import { Component } from 'vue';
import Vuex from 'vuex';
import { createLocalVue, shallowMount } from '@vue/test-utils';
import numericOnly from '@/directives/input-numeric-only';

const localVue = createLocalVue();
localVue.use(Vuex);

localVue.directive('numericOnly', numericOnly);

describe('Directives Input-Numeric-Only', () => {

let component: Component;
let wrapper: any;

beforeEach(() => {
    component = {
        template: `
            <input type="text" id="inputNumericOnly" v-numericOnly
                v-bind:value="inputValue" @input="updateInput($event)" />
        `,
        data() {
            return {
                inputValue: 0,
            };
        },
        methods: {
            updateInput($event: any) {
                console.log('Input Change....', $event.target.value);
            },
        },
    };
    wrapper = shallowMount(component, {
        localVue,
    });
});

it('Check if char key is pressed', () => {
    wrapper.find('input').trigger('keydown', {
        which: 65,
    });
    expect(wrapper.vm.inputValue).toBe('a');
});
});
从“vue”导入{Component};
从“Vuex”导入Vuex;
从'@vue/test-utils'导入{createLocalVue,shallowMount};
仅从“@/指令/仅输入数字”导入数字;
const localVue=createLocalVue();
localVue.use(Vuex);
localVue.directive('numerionly',numerionly);
描述('指令仅输入数字',()=>{
let组件:组件;
让我们看看:任何;
在每个之前(()=>{
组件={
模板:`
`,
数据(){
返回{
输入值:0,
};
},
方法:{
更新输入($event:any){
log('Input Change…',$event.target.value);
},
},
};
包装=浅装(组件{
localVue,
});
});
它('检查是否按下了字符键',()=>{
wrapper.find('input').trigger('keydown'{
其中:65,,
});
expect(wrapper.vm.inputValue).toBe('a');
});
});
我希望输入值会更改,但不会对其产生影响。

您可以尝试@keydown.native=“updateInput($event)”而不是@input=“updateInput($event)”吗