vue.js - 使用Vue CLI3.0创建多页面应用程序,如何处理这个错误?
问题描述
我是 Vue 的初学者,我正在尝试使用 Vue 构建一个多页 Web 应用程序以进行练习。但是我在下面遇到了这个问题:
Failed to compile.
./src/index/views/Home.vue?vue&type=script&lang=js& (./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/index/views/Home.vue?vue&type=script&lang=js&)
Module not found: Error: Can't resolve '@/components/HelloWorld.vue' in '/home/Username/Web/wk_front_end/src/index/views'
这是我项目的文件树,每个文件都是vue生成的,因为我只想测试多页,所以我认为不会是编码问题。
这是我所做的:
index
我在该文件夹下创建了一个名为 的src
文件夹,然后我将原来的所有文件和文件夹移动src
到,index
因为我希望components
和assets
只在相应的页面中使用。
我vue.config.js
的是:
module.exports = {
pages: {
index: {
entry: "src/index/main.js",
template: "src/index/index.html",
filename: "index.html",
title: "Index Page"
},
}
}
当我尝试运行它时,我在 chrome 窗口上收到了上面的错误。实际上,错误是:
我认为这可能是由于缺少配置造成的,但我真的无法弄清楚我需要哪些其他配置。
以前有没有人有类似的问题?有谁知道如何解决它?或者,有没有人有一些成功的多页示例,我可以看看?
真的感谢您的帮助。
解决方案
在我看来,您可能错误地导入了 Vue 组件。如果您想制作多页应用程序,为什么不尝试vue-router呢?也许这不是您问题的直接解决方案,但它将帮助您在未来更好地管理您的页面(路线)。
推荐阅读
- mysql - 如何在数据库初始化完成后停止填充卷的 MySQL docker 容器?
- javascript - Api fetch - 无法读取未定义的属性“json”
- sql - SQLite 如何水平堆叠组?
- git - git - 如何为 git prune 创建一个无法访问的提交?
- python - 查找最近的素数python
- google-analytics - 如何在 Google Analytics Enhanced Ecommerce 中转义撇号
- bash - 为什么在排序后选择唯一出现的结果与仅选择唯一出现的结果不同?
- javascript - 切换到 https 后,什么会阻止表单/ API 调用?
- python - 使用字符串创建类函数
- html - 反转悬停时从文本中显示的图像