I try to fetch a json file in a custom plugin in Vue. But the prototype created in the plugin cannot be ready yet before other components attempt to use it in mounted().
So, what am I doing wrong? Couldn't find anything remarkable in StackOverflow.
app.js
import Vue from "vue"
const Url = require("@/plugins/Url")
Vue.use(Url)
Url.js
import djangoJsReverse from "django-js-reverse"
export default {
async install(Vue, options) {
Vue.PLUGIN_VERSION = "0.0.1"
console.log("pre install")
const response = await fetch("/jsreverse/")
const data = await response.json()
console.log("post install")
Vue.prototype.$urls = djangoJsReverse(data)
}
}