我如何在我的 vue 中使用我的组件方法?

How can i use my component method in my vue?

我在这个组件中有一个方法 "aggiornaQuantity",我将在我的 vue 中使用它。我能怎么做? 显然我做了各种测试都没有成功

Vue.component('todo-item', {
    props: ['todo'],
    template: '...',
    methods: 
   {
     aggiornaQuantity: function() 
      {
       return this.todo.quantity = this.value ;
      }
    }  

var app7 = new Vue
   (
      {
         el: '#app-7',
         data:
         {
            message: '${Message}',
            risultato: true,
            groceryList: [],
            product: '',
            selected: '',
         },
         methods:
         {
           .....
         }

编辑:我不确定您是否想知道如何使用该功能或​​为什么您的功能不起作用(如上所述)。如果是前者,答案如下:


您必须在 lifecycle instances 之一中调用它。大多数时候,我们在 mounted().

中调用它
...
methods: {
  foo () {
    // do something
  },
},
mounted() {
  this.foo();
},
...