我试图用 MCVE 复制 this question,但我无法在 <script>
的 index.html
标签中使用 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]
答案 0 :(得分:1)
最后调用 .mount(elementId)
使其工作
const app = Vue.createApp({
setup() {
console.log("foo")
}
})
app.mount("#app")