Can I call mixin function from asyncData()
method of the page component with Nuxt.js?
My code:
<template>
...
</template>
<script>
import api from "@/plugins/api/api.js"
...
export default {
...
async asyncData(context) {
...
context.apiMethodName()
...
}
...
}
...
</script>
api.js
import Vue from 'vue'
import API from '@/assets/js/api'
Vue.mixin({
methods: {
apiMethodName() { ... }
}
})
You cant call vue methods from withing asyncData, because asyncData executed before vue have an instance.
You can extract method into simple js function and call it both in asyncData and your vue method, but keep in mind that in asyncData you wont be able to access vue instance properties and other methods
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With