0

I'm confused about the difference between the CLI version of Vue.js and the normal version where you use a Vue istance.

On the initial build, the App.js file looks something like this:

import { createApp } from 'vue'
import { App } from './App.vue'

createApp(App).mount('#app')

and the app works fine.

But if I try to change it slightly and use:

import { Vue } from 'vue'
import { App } from './App.vue'

Vue.createApp(App).mount('#app')

all I get is a blank page.

I've been wanting to add a prototype to the Vue instance to access a global variable, but I don't see how if you can't use the Vue class normally.

What's the difference in functionality on the vue-cli when using Vue.createApp and createApp?

2
  • @BoussadjraBrahim I see that my app does work when using createApp vs Vue.createApp, but I don't understand why it works. Commented Aug 24, 2021 at 9:01
  • 1
    the first syntax is the correct one because there's no import { Vue } from 'vue' in vue 3, and Vue.createApp is valid only when using vue 3 via CDN Commented Aug 24, 2021 at 9:12

1 Answer 1

1

Since you're using the vue cli, the first syntax is correct because there's no Vue object imported from vue, for more explanation check this answer. To add a global variable try to use app.config.globalProperties.$globalVar :

import { createApp } from 'vue'
import { App } from './App.vue'

let app=createApp(App)
app.config.globalProperties.$globalVar=555;
app.mount('#app')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.