Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vue.js - Typescript: Expected method shorthand in object literal

inside my input component, I have this code in order to make the v-model on the input works as a component:

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

This is the official example: https://v2.vuejs.org/v2/guide/components-custom-events.html#Binding-Native-Events-to-Components

Now Typescript return me this Warning:

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

Do you know the code solution?

like image 628
Alessandro Colombo Avatar asked Nov 07 '25 00:11

Alessandro Colombo


1 Answers

Use method shorthand format: inputListeners() { ... }

computed: {
  inputListeners() {
    ...
  }
}
like image 188
Sajib Khan Avatar answered Nov 09 '25 09:11

Sajib Khan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!