博主信息
博文 119
粉丝 3
评论 1
访问量 121183
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
VUE 创建项目流程
赵大叔
原创
975人浏览过

安装 vue3

  • yarn 需要电脑有安装,https://www.jianshu.com/p/1f920de5f941

1、安装 vue-cli 脚手架,全局安装

  • yarn: yarn global add @vue/cli
  • npm: npm install -g @vue/cli

卸载

  • yarn: yarn global remove @vue/cli
  • npm: npm uninstall vue-cli -g

2、一次性安装 3 个 vue-cli 服务

  • yarn: yarn global add @vue/cli @vue/cli-service-global @vue/cli-service
  • npm: npm install -g @vue/cli @vue/cli-service-global @vue/cli-service

如果安装失败,可能是没有权限,macbook 命令行前加 sudo

创建项目

  1. # 1、创建一个项目
  2. vue create vuecli, vuecli-项目名称
  3. # 2、选择:用vue2,vue3,手动配置。 vue2,vue3除了基本语法, 还有下面2个功能
  4. # 2.1、babel 把es6的语法,转成es5的语法,可以做到兼容
  5. # 2.2、eslint 语法检查,约束你的代码习惯
  6. # 第一次一般选择手动选择
  7. please pick a preset
  8. Default ([Vue 2] babel, eslint)
  9. Default (Vue 3) ([Vue 3] babel, eslint)
  10. Manually select features
  11. # 3、手动选择功能:Choose Vue version、Babel、CSS Pre-processors
  12. Check the features needed for your project:
  13. Choose Vue version // (*)版本
  14. Babel // (*)把es6的语法,转成es5的语法,可以做到兼容
  15. TypeScript // 由微软开发的自由和开源的编程语言,是 JavaScript 的一个超集,支持es6语法
  16. Progressive Web App (PWA) Support // Web APP开发
  17. Router // (*)路由
  18. Vuex // (*)状态管理器
  19. CSS Pre-processors // css预处理器:三种流行的CSS预处理器:Sass、LESS 和 Stylus
  20. Linter / Formatter // 语法检查器(eslint)
  21. Unit Testing // 单元测试
  22. E2E Testing // e2e(端到端)测试
  23. // Mac电脑
  24. Babel
  25. TypeScript
  26. Progressive Web App (PWA) Support
  27. Router
  28. Vuex
  29. CSS Pre-processors
  30. Linter / Formatter
  31. Unit Testing
  32. E2E Testing
  33. # 4、选择版本:3.x
  34. Choose a version of Vue.js that you want to start the project with:
  35. 2.x
  36. 3.x // (*)
  37. # 5、选择css预处理器版本:dart-sass,官方目前主力推dart-sass
  38. Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default):
  39. Sass/SCSS (with dart-sass) // (*)
  40. Sass/Scss (with node-sass)
  41. Less
  42. Stylus
  43. - Mac
  44. Use history mode for router? (Requires proper server setup for index fallback in production) (Y/n) // Y
  45. # 6、配置文件:In package.json
  46. Where do you prefer placing config for Babel, ESlint, etc.?
  47. In dedicated config files // 独立配置文件
  48. In package.json // (*)放在package.json里
  49. # 7、是否保持此项目配置:保存的话,起个名字,后续直接安装这个
  50. Save this as a preset for future projects?
  51. y // 保存
  52. n // 不保存

运行项目

  • yarn: yarn serve
  • npm: npm run serve

安装常用插件

  • 安装 ant D: 需要安装.3版本
  1. # 1、npm安装
  2. npm i --save ant-design-vue@next
  3. # 2、yarn安装
  4. yarn add ant-design-vue@next
  5. yarn add ant-design-vue@3.2.2
  • 添加 axios: yarn add axios

配置接口

  • src 目录下新建network文件夹
  • network 文件夹新建request.js文件, 做接口统一处理
  1. import axios from "axios";
  2. export function request(config){
  3. const instance = axios.create({
  4. baseURL : "https://help10086.io/admin/",
  5. timeout : 5000,
  6. })
  7. // 请求拦截
  8. instance.interceptors.request.use(
  9. (config) => {
  10. return config
  11. },
  12. (err) => {
  13. console.log(err);
  14. }
  15. );
  16. // 响应拦截
  17. instance.interceptors.response.use(
  18. (res) => {
  19. return res.data;
  20. },
  21. (err) => {
  22. console.log(err);
  23. }
  24. );
  25. return instance(config);
  26. }
  • 接口文件中引入request
  1. import { request } from "./request.js";
  2. export function users_li(data={}){
  3. return request( {
  4. url : "users_li",
  5. method : "post",
  6. data
  7. })
  8. }

项目打包: yarn build

项目上线

  • 打包好的dist文件夹上传到网站
  • 需要配置网站 php 伪静态文件
  1. <IfModule mod_rewrite.c>
  2. Options +FollowSymlinks -Multiviews
  3. RewriteEngine On
  4. RewriteCond %{REQUEST_FILENAME} !-d
  5. RewriteCond %{REQUEST_FILENAME} !-f
  6. RewriteRule ^(.*)$ index.html [L,E=PATH_INFO:$1]
  7. </IfModule>
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学