[英]Vue.js: How to call method from another exported constent
I am exporting set of constants and using it as mixin. 我正在导出一组常量,并将其用作mixin。 I am not sure how to call methods from different exported constant?
我不确定如何从不同的导出常量调用方法?
mixins.js mixins.js
export const exConstOne = {
methods: {
fnOne () {
console.log('exConstOne > fnOne got fired')
}
}
}
export const exConstTwo = {
methods: {
fnTwo () {
exConstOne.fnOne()
}
},
mounted () {
this.fnTwo()
}
}
MyComponent.vue MyComponent.vue
<script>
import { exConstTwo } from './mixins'
export default {
name: 'MyComponent',
mixins: [exConstTwo],
}
</script>
You forgot the "methods" in your function call. 您忘记了函数调用中的“方法”。
If you change your code for the following it will work 如果您更改以下代码,它将起作用
mixin.js mixin.js
export const exConstOne = {
methods: {
fnOne () {
console.log('exConstOne > fnOne got fired')
}
}
}
export const exConstTwo = {
methods: {
fnTwo () {
exConstOne.methods.fnOne()
}
},
mounted () {
this.fnTwo()
}
}
Note : The issue is not really Vue related. 注意 :该问题与Vue无关。 It's just a javascript mistake.
这只是一个JavaScript错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.