使用Vue-Cli构建前端项目教程

需积分: 6 0 下载量 68 浏览量 更新于2024-08-05 收藏 7KB TXT 举报
"这篇文档是关于使用Vue CLI创建前端项目的教程,适合初学者。文档提到了如何安装Node.js环境、使用npm和cnpm,以及如何通过Vue CLI搭建项目。此外,还介绍了创建Vue项目的步骤,包括使用Vue UI或命令行接口(CLI),设置路由,以及在项目中使用Vue Router进行页面跳转。最后,文档简要提到了前端框架与项目整合,特别是如何安装axios和处理跨域问题。" 在这个文档中,我们首先学习了如何搭建Vue开发环境。这包括安装Node.js,因为npm(Node包管理器)会随着Node.js一起安装。由于npm的服务器在国外,国内用户可以使用cnpm(中国npm镜像)来加速包的下载。要安装Vue CLI,我们可以使用全局安装命令`npm install -g @vue/cli`,或者使用cnpm替代。Vue CLI提供了Vue UI界面,方便用户可视化地创建和配置项目。 文档接着描述了如何创建一个新的Vue项目。通过命令行,我们可以运行`vue create vue-project-02`来创建名为`vue-project-02`的新项目。创建完成后,可以使用`cd`命令进入项目目录,并运行`npm run serve`启动开发服务器。为了在项目中创建新的页面和管理路由,我们需要编辑`router/index.js`文件,定义路由规则并导入对应的组件。 文档中还展示了如何在Vue组件中使用`<router-link>`和`this.$router.push()`来进行页面间的导航。`<router-link>`用于定义链接,而`this.$router.push()`则在方法中用于程序化的页面跳转。 在讨论前端框架整合时,文档提到了axios,这是一个常用的HTTP库,用于发送HTTP请求。安装axios可以使用`npm install axios`命令。如果遇到跨域问题,文档建议禁用SSL严格检查(`npm config set strict-ssl false`),并安装supervisor以方便调试。跨域问题通常需要在前端和后端都进行配置,前端通常通过axios的配置来设定基础URL。 这份文档提供了从零开始使用Vue CLI创建和管理前端项目的基础教程,对于初学者来说是一份不错的学习资料。

npm ERR! code ERESOLVE npm ERR! ERESOLVE could not resolve npm ERR! npm ERR! While resolving: vue-router@4.2.1 npm ERR! Found: vue@2.7.14 npm ERR! node_modules/vue npm ERR! peerOptional vue@"*" from @vue/babel-preset-jsx@1.4.0 npm ERR! node_modules/@vue/babel-preset-jsx npm ERR! @vue/babel-preset-jsx@"^1.0.0" from @vue/babel-preset-app@3.12.1 npm ERR! node_modules/@vue/babel-preset-app npm ERR! @vue/babel-preset-app@"^3.12.1" from @vue/cli-plugin-babel@3.12.1 npm ERR! node_modules/@vue/cli-plugin-babel npm ERR! dev @vue/cli-plugin-babel@"^3.10.0" from the root project npm ERR! vue@"^2.7.14" from the root project npm ERR! 1 more (vuex) npm ERR! npm ERR! Could not resolve dependency: npm ERR! peer vue@"^3.2.0" from vue-router@4.2.1 npm ERR! node_modules/vue-router npm ERR! vue-router@"^4.2.1" from the root project npm ERR! npm ERR! Conflicting peer dependency: vue@3.3.4 npm ERR! node_modules/vue npm ERR! peer vue@"^3.2.0" from vue-router@4.2.1 npm ERR! node_modules/vue-router npm ERR! vue-router@"^4.2.1" from the root project npm ERR! npm ERR! Fix the upstream dependency conflict, or retry npm ERR! this command with --force or --legacy-peer-deps npm ERR! to accept an incorrect (and potentially broken) dependency resolution. npm ERR! npm ERR! npm ERR! For a full report see: npm ERR! C:\Users\11833\AppData\Local\npm-cache\_logs\2023-05-29T06_00_03_754Z-eresolve-report.txt npm ERR! A complete log of this run can be found in: C:\Users\11833\AppData\Local\npm-cache\_logs\2023-05-29T06_00_03_754Z-debug-0.log

2023-05-30 上传
2023-07-22 上传

npm ERR! code ERESOLVE npm ERR! ERESOLVE could not resolve npm ERR! npm ERR! While resolving: @vue/cli-plugin-vuex@4.4.6 npm ERR! Found: @vue/cli-service@5.0.8 npm ERR! node_modules/@vue/cli-service npm ERR! dev @vue/cli-service@"^5.0.8" from the root project npm ERR! peer @vue/cli-service@"^3.0.0 || ^4.0.0 || ^5.0.0-0" from @vue/cli-plugin-babel@5.0.8 npm ERR! node_modules/@vue/cli-plugin-babel npm ERR! dev @vue/cli-plugin-babel@"^5.0.8" from the root project npm ERR! 3 more (@vue/cli-plugin-pwa, @vue/cli-plugin-router, @vue/cli-plugin-vuex) npm ERR! npm ERR! Could not resolve dependency: npm ERR! peer @vue/cli-service@"^3.0.0 || ^4.0.0-0" from @vue/cli-plugin-vuex@4.4.6 npm ERR! node_modules/@vue/cli-plugin-vuex npm ERR! dev @vue/cli-plugin-vuex@"~4.4.0" from the root project npm ERR! npm ERR! Conflicting peer dependency: @vue/cli-service@4.5.19 npm ERR! node_modules/@vue/cli-service npm ERR! peer @vue/cli-service@"^3.0.0 || ^4.0.0-0" from @vue/cli-plugin-vuex@4.4.6 npm ERR! node_modules/@vue/cli-plugin-vuex npm ERR! dev @vue/cli-plugin-vuex@"~4.4.0" from the root project npm ERR! npm ERR! Fix the upstream dependency conflict, or retry npm ERR! this command with --force or --legacy-peer-deps npm ERR! to accept an incorrect (and potentially broken) dependency resolution. npm ERR! npm ERR! npm ERR! For a full report see: npm ERR! C:\Users\35514\AppData\Local\npm-cache\_logs\2023-06-08T07_30_06_817Z-eresolve-report.txt npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\35514\AppData\Local\npm-cache\_logs\2023-06-08T07_30_06_817Z-debug-0.log

2023-06-09 上传