【问题标题】:Vue.js - Typescript: Expected method shorthand in object literalVue.js - Typescript:对象文字中的预期方法简写
【发布时间】:2019-01-17 17:41:49
【问题描述】:

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

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

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

现在 Typescript 向我返回此警告:

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

你知道代码解决方案吗?

【问题讨论】:

  • 这只是一个 linter 警告;您可以按照建议重写对象:inputListeners() { 而不是您所拥有的 (inputListeners: function () {
  • 我做到了 -- inputListeners(this) { -- 它修复了警告。谢谢

标签: typescript vue.js


【解决方案1】:

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

computed: {
  inputListeners() {
    ...
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-18
    • 1970-01-01
    • 2023-04-04
    • 2019-10-11
    • 2021-06-06
    相关资源
    最近更新 更多