gpt4 book ai didi

javascript - Vue CLI 生成空正文,错误为 : Cannot find element: #app after migration vuecli 2>3

转载 作者:行者123 更新时间:2023-12-01 02:19:08 26 4
gpt4 key购买 nike

我正在尝试将我的 VueJS 项目从 VueCLI 2 迁移到 3。所有文件都复制到 src 文件夹中。当我尝试使用 npm runserve 在浏览器中查看它时,我得到这个 HTML,没有 <div id="app">目前:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Webpack App</title>
<link rel="preload" as="script" href="/app.js">
<link rel="icon" type="image/png" sizes="32x32" href="/img/icons/favicon-32x32.png"><link rel="icon" type="image/png" sizes="16x16" href="/img/icons/favicon-16x16.png"><link rel="manifest" href="/manifest.json">
<meta name="theme-color" content="#4DBA87"><meta name="apple-mobile-web-app-capable" content="yes"><meta name="apple-mobile-web-app-status-bar-style" content="black"><meta name="apple-mobile-web-app-title" content="iris-vue2"><link rel="apple-touch-icon" href="/img/icons/apple-touch-icon-152x152.png"><link rel="mask-icon" href="/img/icons/safari-pinned-tab.svg" color="#4DBA87"><meta name="msapplication-TileImage" content="/img/icons/msapplication-icon-144x144.png"><meta name="msapplication-TileColor" content="#000000">
</head>
<body>
<script type="text/javascript" src="/app.js"></script>
</body>
</html>

控制台出现此错误:

vue.runtime.esm.js?ff9b:587 [Vue warn]: Cannot find element: #app

HTML 从哪里呈现?在之前版本的 VueCLI 中,有一个 index.html 文件。现在不见了?

在我的 main.js 中,我在初始化新项目时执行与样板中相同的操作:

new Vue({
i18n,
router,
store,
render: h => h(App)
}).$mount('#app')

最佳答案

我明白了!新的index.html 不再位于根目录中。在 VueCli 3 中,它位于 /public 文件夹中!

所以我必须将/index.html 移动到/public/index.html。

关于javascript - Vue CLI 生成空正文,错误为 : Cannot find element: #app after migration vuecli 2>3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49339191/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com