Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vue 3: Vue.createApp is not a constructor

Tags:

vue.js

vuejs3

I am brand new to Vue and am trying to learn how to use it.

I think I am getting tripped up trying to mount a new Vue app.

Here is what I can get to work:

<script src="https://unpkg.com/vue"></script>
<script>
const vm = new Vue({})
</script>

from there I am able to mount it and use everything correctly.

However, this currently loads an older version of Vue (2.6.7)

I'd like to learn on the newest version (Vue 3) so I tried importing the package recommended by Vue docs:

<script src="https://unpkg.com/vue@next"></script>
<script>
const vm = new Vue({})
</script>

and I get the following error in console:

Uncaught TypeError: Vue is not a constructor

I also tried mimicking the syntax from Vue 3's docs.

<script src="https://unpkg.com/vue@next"></script>
<script>
const vm = new Vue.createApp({})
</script>

but it throws the same error:

Uncaught TypeError: Vue.createApp is not a constructor

Using a different CDN or a specific version ([email protected]) also gives me the same result.

What am I doing wrong?

like image 734
Adam Starrh Avatar asked Nov 24 '20 20:11

Adam Starrh


1 Answers

createApp is not an object it's a function that returns an instance of vue app, so it should be :

 const vm = Vue.createApp({}) //remove the new

createApp
Returns an application instance which provides an application context. The entire component tree mounted by the application instance share the same context
const app = Vue.createApp({})

like image 188
Boussadjra Brahim Avatar answered Oct 04 '22 22:10

Boussadjra Brahim