Vue3 提供的语法提示功能插件 – Volar Node.js 的下载 中文官网:https://nodejs.org/zh-cn
镜像站点:https://npmmirror.com/mirrors/node/
更换 npmmirror 镜像源 修改 npm 至新的淘宝镜像源:
1 npm config set registry https://registry.npmmirror.com
查看当前使用的镜像地址命令
如果返回 https://registry.npmmirror.com 说明镜像配置成功。
使用 pnpm 代替 npm 通过 npm安装,也可以在官网查看其他安装方式
Windows 系统
1 2 3 4 1.Windows 系统 npm install -g pnpm 2.Mac 系统 sudo npm install -g pnpm
Vue 项目启动套件 Fantastic-startkit 官方文档
使用本套件前,需要在本地依次安装好 Node.js , pnpm , Git 和 Visual Studio Code 。
Node.js 需要使用 14.18+ / 16+ 版本,建议为 18.12+ 版本。
然后在 Visual Studio Code 里安装好以下扩展:
使用 Vite 构建 vue 项目的方法 安装 Vue3+Pinia+VueRouter 1 2 3 npm init vue@latest 或者 pnpm create vue
依次需要配置项目名 、选择自己需要的插件
cd vue3 进入创建的项目包
npm i/ yarn /pnpm下载项目所需的依赖
npm run dev / yarn dev /pnpm dev运行项目
到这一个 vite + vue 的项目最基本的框架就已经搭建完成了
代码联想提示路径 我们在使用 fileURLToPath的时候没有提示,我们需要安装一下node的类型库
在vite.config.js中填写
1 2 3 4 5 6 7 8 9 import { fileURLToPath } from 'url' export default { resolve :{ alias :{ "@" : fileURLToPath (new URL ('src' , import .meta .url )) } } }
配置完成后,我们在项目中尝试引用,发现并没有路径提示,那么我们还需要在 jsconfig.json中做一下配置
1 2 3 4 5 6 7 8 9 { "compilerOptions" : { "baseUrl" : "./" , "paths" : { "@/*" : [ "src/*" ] } } }
Eslint代码规范 首先安装 Eslint
生成配置文件
1 2 //生成配置文件,.eslintrc.js npx eslint --init
@antfu/eslint-config基础配置 更多配置请访问 antfu/eslint-config
安装 1 pnpm add -D eslint @antfu/eslint-config
配置 1 2 3 4 //在根目录下的 `.eslintrc` { "extends": "@antfu" }
vscode自动保存修复 首先要安装 VS Code ESLint extension 然后创建 .vscode/settings.json 1 2 3 4 5 6 7 { "prettier.enable" : false , "editor.formatOnSave" : false , "editor.codeActionsOnSave" : { "source.fixAll.eslint" : true } }
Sass 预处理的安装 为什么使用 sass 可以查看 Sass 和 Less 的区别和使用
1 pnpm install --save-dev sass
按需导入插件的配置 按需导入 vue 和 vue-router 相关函数 + Element Plus
需要用到两个插件 unplugin-vue-components、``unplugin-auto-import这两个插件。
首先安装这两个插件
1 2 3 4 1.安装按需导入插件 pnpm i unplugin-vue-components unplugin-auto-import -D 2.安装ElementPlus pnpm install element-plus
然后配置 vite.config.js,我的配置如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 import { fileURLToPath, URL } from 'node:url' import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' import AutoImport from 'unplugin-auto-import/vite' import Components from 'unplugin-vue-components/vite' import { ElementPlusResolver } from 'unplugin-vue-components/resolvers' export default defineConfig ({ plugins : [ vue (), AutoImport ({ imports : ['vue' , 'vue-router' ], resolvers : [ElementPlusResolver ()], }), Components ({ dirs : ['src/components/' ], extensions : ['vue' ], resolvers : [ElementPlusResolver ()], }), ], resolve : { alias : { '@' : fileURLToPath (new URL ('./src' , import .meta .url )), }, }, })
Axios 的安装及二次封装 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 1. 安装`Axios` pnpm install axios 2. 在 scr 目录下新建 `utils/request.js` import axios from 'axios' const service = axios.create ({ baseURL : 'https://some-domain.com/api/' , timeout : 3000 , }) service.interceptors .request .use ( (config ) => { return config }, (error ) => { Promise .reject (error) } ) service.interceptors .response .use ( (response ) => { return response.data }, (error ) => { return Promise .reject (error) } ) export default service
重置默认样式 Normalize CSS: 点击查看更多1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 html { line-height : 1.15 ; -webkit-text-size-adjust: 100% ; } body { margin : 0 ; } main { display : block; } h1 { font-size : 2em ; margin : 0.67em 0 ; } hr { box-sizing : content-box; height : 0 ; overflow : visible; } pre { font-family : monospace, monospace; font-size : 1em ; } a { background-color : transparent; } abbr [title] { border-bottom : none; text-decoration : underline; text-decoration : underline dotted; } b ,strong { font-weight : bolder; } code ,kbd ,samp { font-family : monospace, monospace; font-size : 1em ; } small { font-size : 80% ; } sub, sup { font-size : 75% ; line-height : 0 ; position : relative; vertical-align : baseline; } sub { bottom : -0.25em ; } sup { top : -0.5em ; } img { border-style : none; } button ,input ,optgroup, select, textarea { font-family : inherit; font-size : 100% ; line-height : 1.15 ; margin : 0 ; } button ,input { overflow : visible; } button ,select { text-transform : none; } button ,[type='button' ] ,[type='reset' ] ,[type='submit' ] { -webkit-appearance: button; } button ::-moz-focus-inner,[type='button' ]::-moz-focus-inner, [type='reset' ]::-moz-focus-inner, [type='submit' ]::-moz-focus-inner { border-style : none; padding : 0 ; } button :-moz-focusring,[type='button' ]:-moz-focusring, [type='reset' ]:-moz-focusring, [type='submit' ]:-moz-focusring { outline : 1px dotted ButtonText; } fieldset { padding : 0.35em 0.75em 0.625em ; } legend { box-sizing : border-box; color : inherit; display : table; max-width : 100% ; padding : 0 ; white-space : normal; } progress { vertical-align : baseline; } textarea { overflow : auto; } [type='checkbox' ] ,[type='radio' ] { box-sizing : border-box; padding : 0 ; } [type='number' ] ::-webkit-inner-spin-button,[type='number' ]::-webkit-outer-spin-button { height : auto; } [type='search' ] { -webkit-appearance: textfield; outline-offset : -2px ; } [type='search' ] ::-webkit-search-decoration { -webkit-appearance: none; } ::-webkit-file-upload-button { -webkit-appearance: button; font : inherit; } details { display : block; } summary { display : list-item; } template { display : none; } [hidden] { display : none; }
常用工具库整合 @vueuse/core 是一个包,封装了常见的一些交互逻辑
官方地址:https://vueuse.org/guide/
中文文档:http://www.vueusejs.com/
1 npm install @vueuse/core
CryptoJS是一个 JavaScript 的加解密的工具包。它支持多种的算法:MD5、SHA1、SHA2、SHA3、RIPEMD-160 哈希散列,进行 AES、DES、Rabbit、RC4、Triple DES 加解密。
Github 地址:https://github.com/brix/crypto-js
Pinna 的数据持久化
官方地址:https://prazdevs.github.io/pinia-plugin-persistedstate/
别人的教程: https://juejin.cn/post/7094552264739651615
1 npm install pinia-plugin-persistedstate
国际化插件:vue-i18n vue3 中使用该插件,需要安装 9 版本的
地址:https://vue-i18n.intlify.dev/
虚拟滚动条插件:nprogress.js github 地址:https://github.com/rstacruz/nprogress
滑动验证码插件 github 地址:https://github.com/lirongtong/miitvip-captcha
动画插件:@vueuse/motion 官方地址:https://motion.vueuse.org/