Stefan_EOX
Stefan_EOX

Reputation: 1531

Use Vue Composition API in a script tag in index.html

I was trying to replicate this question with a MCVE, but I was not able to use the Composition API in a <script> tag in index.html.

This is my index.html:

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <title>Vue3 script</title>
</head>

<body>
  <div id="app">
  </div>
  <script src="https://unpkg.com/vue@next/dist/vue.global.js"></script>
  <script type="module">
    const app = Vue.createApp({
      el: "#app",
      setup() {
        console.log("foo")
      }
    })
  </script>
</body>

</html>

The console only outputs this:

You are running a development build of Vue.
Make sure to use the production build (*.prod.js) when deploying for production.
GET http://127.0.0.1:5500/favicon.ico [HTTP/1.1 404 Not Found 0ms]

Upvotes: 1

Views: 380

Answers (1)

Cheetha
Cheetha

Reputation: 706

Call .mount(elementId) at the end to make it work

const app = Vue.createApp({
      setup() {
        console.log("foo")
      }
    })
    
app.mount("#app")

Upvotes: 2

Related Questions