Blogger Information
Blog 119
fans 3
comment 1
visits 93560
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
VUE 创建项目流程
赵大叔
Original
716 people have browsed it

安装 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>
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!