How can i emit events from a plugin.
-
I am essentially trying to write a plugin with async-functionality i will be needing throughout a lot of my vue components.
And so far it mostly works, but the one thing i cannot seem to figure out is how to emit events from said plugin and act upon these events in my vue components.What i have so far essentially boils down to the following:
import axios from 'axios' function update () { axios.get(`...magic-url...`) .then(response => { this.$emit('update') }) .catch(e => { console.log(e) }) } var api = { update, } export default ({ Vue }) => { Vue.prototype.$foobar = api }
The basic problem is the
this.$emit('update')
inside the axios-call. I assume this is probably because my ‘API’ is not actually aware of anything Vue related but i can’t seem to figure how to go about making this work.I would appreciate any pointers, and perhaps an example of how to act upon these events in vue-components once the
$emit
issue is actually taken care off. -
This post is deleted!