学习视频来自——b站
## 默认目录
|-- undefined
|-- .gitignore
|-- babel.config.js
|-- jsconfig.json
|-- package.json
|-- README.md
|-- vue.config.js
|-- yarn.lock
|-- 开发文档.md
|-- public
| |-- favicon.ico
| |-- index.html
|-- src
|-- App.vue
|-- main.js
|-- assets
| |-- logo.png
|-- components
|-- HelloWorld.vue
## 完善目录
|-- undefined
|-- .gitignore
|-- babel.config.js
|-- directoryList.md
|-- jsconfig.json
|-- package.json
|-- README.md
|-- vue.config.js
|-- yarn.lock
|-- 开发文档.md
|-- mock/ // 模拟数据
|-- public/
| |-- favicon.ico
| |-- index.html
|-- src/
| |-- App.vue
| |-- main.js
| |-- api/
| |-- assets/ // 静态资源目录
| | |-- logo.png
| | |-- icons // svg
| | |-- images
| |-- components/ // 公共组件目录
| | |-- HelloWorld.vue
| |-- router/ // 路由配置目录
| |-- store/ // 状态管理目录
| |-- styles/ // 公共样式目录
| |-- utils/ // 工具函目录
| |-- views/ // 页面目录
|-- static // 静态资源目录,不会被打包
yarn add vue-router --save
配置一下路由,显示在页面中
App.vue
views/Home.vue 随便写点文字
router/index.js
import { createRouter, createWebHashHistory } from "vue-router";
const routes = [
{
path: "/",
name: "home",
component: () => import("../views/Home.vue"),
},
];
const router = createRouter({
history: createWebHashHistory(),
routes,
});
export default router;
main.js
import router from "@/router/index";
const app = createApp(App);
app.use(router);
app.mount("#app");

yarn add vuex@next --save
yarn add less less-loader --save
yarn add axios --save
yarn add vue-axios --save
main.js
import axios from "axios";
import VueAxios from "vue-axios";
app.use(VueAxios, axios);
app.provide('axios', app.config.globalProperties.axios)
App.vue
<script setup>
import { onMounted, inject } from "vue";
const axios = inject("axios"); //注入一下不然不能用
onMounted(() => {
getPhoto();
});
const getPhoto = () => {
axios.get("https://api.uomg.com/api/rand.qinghua?format=json").then((res) => {
console.log(res);
});
};
</script>

vue-cli4中引入全局less变量的方式
styles/commons.less
// --------- Colors -----------
@primary-color: #3873F8; // 全局主色
@link-color: #1890ff; // 链接色
@success-color: #229F87; // 成功色
@warning-color: #F67778; // 警告色
@error-color: #F35248; // 错误色
// --------- 中性色 -----------
@gray-0: #202020;
@gray-1: #585858;
@gray-2: #949494;
@gray-9: #F6F6F8;
@gray-10: #ffffff;
// --------- font -----------
@font-12: 12px;
@font-14: 14px;
@font-16: 16px;
// --------- 间距 -----------
@padding-4: 4px;
@padding-8: 8px;
@padding-12: 12px;
@padding-20: 20px;
// 全局控制
body {
padding: 0;
margin: 0;
line-height: 1.5;
color: @gray-0;
font-size: @font-14;
transition: all 0.3s;
font-family: Avenir, Helvetica, Arial, sans-serif;
}
p {
padding: 0;
margin: 0;
}
li {
list-style: none;
}
img {
padding: 0;
margin: 0;
display: block; // flex布局变成块可能更好
}
a {
text-decoration: none;
&:hover {
text-decoration: underline;
}
}
input, textarea {
outline: none;
}
vue.config.js
const { defineConfig } = require("@vue/cli-service");
const { resolve } = require("path");
module.exports = defineConfig({
transpileDependencies: true,
lintOnSave: false,
pluginOptions: {
"style-resources-loader": {
preProcessor: "less",
patterns: [resolve(__dirname, "./src/styles/commons.less")], //引入全局less文件
},
},
});
vue导入图标的3种方式【阿里图标】
vue引用阿里彩色图标(symbol引用)
综合两篇博客所述 我决定使用第三种方式 .svg(第一篇博客中所介绍的)
yarn add svg-sprite-loader
svg放在src/assets/icon/svg目录下
vue.config.js
const { defineConfig } = require("@vue/cli-service");
const path = require("path");
const webpack = require("webpack");
function resolve(dir) {
return path.join(__dirname, dir);
}
module.exports = defineConfig({
// eslint-loader 是否在保存的时候检查
lintOnSave: false,
// 部署应用包时的基本 URL,用法和 webpack 本身的 output.publicPath 一致
publicPath: "./",
// 输出文件目录
outputDir: "dist",
// 是否使用包含运行时编译器的 Vue 构建版本
runtimeCompiler: false,
// 生产环境是否生成 sourceMap 文件
productionSourceMap: false,
// 生成的 HTML 中的 和