在 index.html 的脚本标签中使用 Vue Composition API

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

我试图用 MCVE 复制 ,但我无法在 index.html<script> 标签中使用 Composition API。

这是我的 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>

控制台只输出这个:

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]

在最后调用 .mount(elementId) 使其工作

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