admin管理员组文章数量:1191752
I'm doing everything by the docs, but, still having an error in the console. What I'm trying is to create a global variable of a Firebase instance.
main.js
:
import { createApp } from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import firebase from 'firebase'
require('firebase/firestore')
const config = {
// config
}
firebase.initializeApp(config)
const app = createApp(App)
.use(store)
.use(router)
.mount("#app");
console.log(app.config) // undefined
app.config.globalProperties.$firebase = firebase;
Why is it undefined
? Or should I overwrite property globalProperties
myself in the config
object?
I'm doing everything by the docs, but, still having an error in the console. What I'm trying is to create a global variable of a Firebase instance.
main.js
:
import { createApp } from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import firebase from 'firebase'
require('firebase/firestore')
const config = {
// config
}
firebase.initializeApp(config)
const app = createApp(App)
.use(store)
.use(router)
.mount("#app");
console.log(app.config) // undefined
app.config.globalProperties.$firebase = firebase;
Why is it undefined
? Or should I overwrite property globalProperties
myself in the config
object?
3 Answers
Reset to default 21const app = createApp(App).use(store).use(router).mount("#app")
returns the root component instance not the app instance which has the field config
, so, you should do:
const app = createApp(App)
const rootComponent = app.use(store)
.use(router)
.mount("#app");
console.log(app.config)
app.config.globalProperties.$firebase = firebase;
Learn more about the differences here.
config
exists on the return value of createApp
instead of the ending mount
call:
const app = createApp(App);
app.use(store).use(router).mount('#app');
console.log(app.config); // Not undefined
I had to do it in this order
const app = createApp({})
app.config.globalProperties.DateUtils = DateUtils
app.use(createVuetify({
components: components,
directives: directives
}))
app.mount("#app")
本文标签: javascriptVue 3appconfig is undefined How to bypass this errorStack Overflow
版权声明:本文标题:javascript - Vue 3 - app.config is undefined. How to bypass this error? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738404021a2084942.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论