如何在 Vue.js 方法函数中设置默认参数值? [英] How can I set default parameter value in Vue.js method function?
本文介绍了如何在 Vue.js 方法函数中设置默认参数值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试为我的组件方法之一中的函数设置默认参数值,例如:
I am trying to set a default parameter value for a function in one of my component methods like:
methods: {
myFuntion(isAction = false) {}
}
但是当调试 isAction 的值时,我得到一个MouseEvent"?
But when debug the value of isAction I get a "MouseEvent"?
推荐答案
我找到了解决方案.看起来该事件也默认传递给该方法.因此,您可以在方法函数上设置默认参数值,例如:
I found the solution. It looks like the event is also passed to the method by default. Therefore you can set a default parameter value on a method function like:
methods: {
myFuntion(event, isAction = false) {
// isAction will be false by default
// event will have the contain the event object
}
}
这篇关于如何在 Vue.js 方法函数中设置默认参数值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文