I have
<template>
<button @click="doSomething">...</button>
</template>
<script>
import ApiService from '../service/api.service';
export default {
setup() {
function doSomething() {
ApiService.doSomething();
}
return {
doSomething
}
}
}
</script>
If I make it shorter (like I'm used in Angular):
<template>
<button @click="ApiService.doSomething">...</button>
</template>
<script>
import ApiService from '../service/api.service';
</script>
It doesn't work, throws a runtime error. (It doesn't work even if I try as function call: @click="ApiService.doSomething()"
Can you help, how to save time/code and directly call ApiService.doSomething just in a template?
P.S. they asked me to post ApiService also so here it is: api.service.js:
import axios from 'axios';
import router from '@/router';
const ApiService = {
init(baseURL) {
axios.defaults.baseURL = baseURL;
},
//...
doSomething() {
router.push({ path: '/goSomewhere' });
},
}
export default ApiService