3👍
✅
If you want to define a class function for SporteventsController
, you need to use the static
keyword:
The
static
keyword defines a static method for a class. Static methods
aren’t called on instances of the class. Instead, they’re called on
the class itself. These are often utility functions, such as functions
to create or clone objects.
(source)
//SporteventsController.js
export default class SporteventsController {
static test() {
console.log("test");
}
}
// component
<template>
<div>
<button @click="testFromController">click</button>
</div>
</template>
<script>
import SporteventsController from "./controller/SporteventsController";
export default {
methods: {
testFromController() {
SporteventsController.test()
}
}
}
</script>
Source:stackexchange.com