Vue3+Element-Plus 前端项目配置
1:创建一个Vue3的项目
Vue3项目创建教程
2:导入element-plus库
element-plus官网:https://element-plus.gitee.io/
1:安装
npm install element-plus --save // --save 表示生产环境也需要
2:配置main.js
以完整引入的方式
3:查看引入效果
在组件中引入一个按钮,确认是否引入成功
上图可以看到引入成功
3:集成Less
1:安装
npm install less less-loader style-resources-loader vue-cli-plugin-style-resources-loader -S
2:配置vue.config.js
const { defineConfig } = require('@vue/cli-service')
const path = require("path"); // 引入path
module.exports = defineConfig({
transpileDependencies: true,
pluginOptions: {
"style-resources-loader": {
preProcessor: "less",
patterns: [path.resolve(__dirname, "./src/assets/less/_variable.less")], // 指定全局变量的配置文件
},
}
})
3:创建less全局变量文件
4:使用全局变量
4:css全局基础配置
1:创建一个基础配置文件src/assets/less/reset.less
* {
margin: 0;
padding: 0;
border: 0;
}
html,
body,
div,
span,
applet,
object,
iframe,
h1,
h2,
h3,
h4,
h5,
h6,
p,
blockquote,
pre,
a,
abbr,
acronym,
address,
big,
cite,
code,
del,
dfn,
em,
img,
ins,
kbd,
q,
s,
samp,
small,
strike,
strong,
sub,
sup,
tt,
var,
b,
u,
i,
center,
dl,
dt,
dd,
ol,
ul,
li,
fieldset,
form,
label,
legend,
table,
caption,
tbody,
tfoot,
thead,
tr,
th,
td,
article,
aside,
canvas,
details,
embed,
figure,
figcaption,
footer,
header,
hgroup,
menu,
nav,
output,
ruby,
section,
summary,
time,
mark,
audio,
video {
font-size: 100%;
font: inherit;
vertical-align: baseline;
box-sizing: border-box;
}
/* HTML5 display-role reset for older browsers */
article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
menu,
nav,
section {
display: block;
}
body {
line-height: 1;
}
ol,
ul {
list-style: none;
}
blockquote,
q {
quotes: none;
}
blockquote:before,
blockquote:after,
q:before,
q:after {
content: "";
content: none;
}
a,
a:hover {
color: inherit;
text-decoration: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
html,
body {
width: 100%;
height: 100%;
background-color: #f5f5f5;
font-family: "PingFangSC-Light", "PingFang SC", "STHeitiSC-Light",
"Helvetica-Light", "Arial", "sans-serif";
}
// 公共样式
.fl {
float: left;
}
.fr {
float: right;
.button-group-item {
padding-left: 3px;
}
}
//清除浮动
.clearfix {
zoom: 1;
&:after {
display: block;
clear: both;
content: "";
visibility: hidden;
height: 0;
}
}
2:引入css全局基础配置
// main.js 中引入
import "./assets/less/reset.less"