【问题标题】:Use Vue Composition API in a script tag in index.html在 index.html 的脚本标签中使用 Vue Composition API
【发布时间】:2021-09-08 01:53:54
【问题描述】:

我试图用 MCVE 复制 this question,但我无法在 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]

【问题讨论】:

    标签: javascript html vue.js vuejs3 vue-composition-api


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2023-02-17
      • 2021-10-24
      • 2021-04-03
      • 2021-08-28
      • 1970-01-01
      • 2023-02-10
      • 2020-11-11
      • 1970-01-01
      • 2022-01-19
      相关资源
      最近更新 更多