Vue.js - Typescript:对象文字中的预期方法速记

Ale*_*mbo 3 typescript vue.js

在我的输入组件中,我有这个代码是为了使输入上的 v-model 作为一个组件工作:

computed: {
inputListeners: function() {
  const vm = this;
  return Object.assign({},
    this.$listeners,
    {
      input: (event: any) => {
        vm.$emit('input', event.target.value);
      },
    },
  );
},
Run Code Online (Sandbox Code Playgroud)

这是官方示例:https : //vuejs.org/v2/guide/components-custom-events.html#Binding-Native-Events-to-Components

现在打字稿给我这个警告:

WARNING in /Users/../components/InputText.vue
Expected method shorthand in object literal ('{inputListeners() {...}}').
> inputListeners: function() {
Run Code Online (Sandbox Code Playgroud)

你知道代码解决方案吗?

Saj*_*han 8

使用方法简写格式: inputListeners() { ... }

computed: {
  inputListeners() {
    ...
  }
}
Run Code Online (Sandbox Code Playgroud)