[英]How can i use my component method in my vue?
I have a method "aggiornaQuantity" in this component that i would use in my vue.我在这个组件中有一个方法“aggiornaQuantity”,我将在我的 vue 中使用它。 How can i do?
我能怎么做? Obviously I did various tests without any success
显然我做了各种测试都没有成功
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:
{
.....
}
Edit: I'm not sure if you want to know how to use the function or why your function doesn't work (as commented above).编辑:我不确定您是否想知道如何使用该功能或您的功能为什么不起作用(如上所述)。 If it's the former, here's the answer:
如果是前者,答案如下:
You have to call it in one of the lifecycle instances .您必须在生命周期实例之一中调用它。 Most of the time, we call it in
mounted()
.大多数时候,我们在
mounted()
中调用它。
...
methods: {
foo () {
// do something
},
},
mounted() {
this.foo();
},
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.