【发布时间】: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