9

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?

1 Answer 1

19

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({})

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.