初始化 scss less
1 项目 通用样式 初始化
1 自定义重置样式代码 公用样式代码
common.less
通用样式
2 normalize.css
npm i normalize.css
normalize.css 可以补充 common 样式 比如 body margin { margin: 0; }
只给body设置颜色会传递给html( margin: 8px; 也看不出来) 分别设置就会 各自有自己的颜色
3 main.js 中导入
import 'normalize.css'
import '@/assets/styles/common.less'
4 或者 取消 3 在 vue.config.js 配置 全局sass变量
在 common 中 引入 @import 'normalize.css'; 或者 直接 vue.config.js--additionalData中配置
css: {
loaderOptions: {
scss: {
additionalData: `@import "~@/assets/styles/common.scss";
@import "normalize.css";`,
},
},
},
还有其他的 ` ; `
重点 !!! 否则无效
App.vue 中 style 必须有内容
<style scope lang="scss">
</style>
自定义样式 变量 每次使用 必须导入
@import "mixins.less";
自动化导入--style-resources-loader
步骤
1 安装 插件 vue add style-resources-loader
选择 less
2 vue.config.js 中 哪些文件自动导入 使用绝对路径
pluginOptions: {
'style-resources-loader': {
preProcessor: 'less',
哪些文件自动导入 使用绝对路径
使用 path.join 来拼接完整路径
patterns: [
path.join(__dirname, './src/assets/styles/variables.less'),
path.join(__dirname, './src/assets/styles/mixins.less'),
],
},
},
src–assets–styles–common.less
* {
box-sizing: border-box;
}
html {
height: 100%;
font-size: 14px;
}
body {
height: 100%;
color: #333;
min-width: 1240px;
font: 1em/1.4 'Microsoft Yahei', 'PingFang SC', 'Avenir', 'Segoe UI',
'Hiragino Sans GB', 'STHeiti', 'Microsoft Sans Serif', 'WenQuanYi Micro Hei',
sans-serif;
}
ul,
h1,
h3,
h4,
p,
dl,
dd {
padding: 0;
margin: 0;
}
a {
text-decoration: none;
color: #333;
outline: none;
}
i {
font-style: normal;
}
input[type='text'],
input[type='search'],
input[type='password'],
input[type='number'],
input[type='checkbox'] {
padding: 0;
outline: none;
border: none;
-webkit-appearance: none;
&::placeholder {
color: #ccc;
}
}
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
-webkit-appearance: none !important;
}
input[type='number'] {
-moz-appearance: textfield;
}
img {
max-width: 100%;
max-height: 100%;
vertical-align: middle;
}
ul {
list-style: none;
}
#app {
background: #f5f5f5;
user-select: auto;
}
.container {
width: 1240px;
margin: 0 auto;
position: relative;
}
.ellipsis {
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
.ellipsis-2 {
word-break: break-all;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
overflow: hidden;
}
.fl {
float: left;
}
.fr {
float: right;
}
.clearfix:after {
content: '.';
display: block;
visibility: hidden;
height: 0;
line-height: 0;
clear: both;
}
.fade {
&-leave {
&-active {
position: absolute;
width: 100%;
transition: opacity 0.5s 0.2s;
z-index: 1;
}
&-to {
opacity: 0;
}
}
}
.fade-right {
&-enter-from,
&-leave-to {
opacity: 0;
transform: translateX(20px);
}
&-enter-active,
&-leave-active {
transition: all 0.5s;
}
&-enter-to,
&-leave-from {
opacity: 1;
transform: translateX(0);
}
}
.xtx-form {
width: 700px;
margin: 0 auto;
padding-left: 190px;
line-height: 50px;
&-item {
display: flex;
align-items: center;
margin-bottom: 25px;
.input {
position: relative;
> i {
position: absolute;
left: 1px;
top: 1px;
width: 49px;
height: 48px;
color: #999;
text-align: center;
line-height: 48px;
font-size: 18px;
}
input {
height: 50px;
width: 320px;
padding-left: 50px;
border: 1px solid #e4e4e4;
border-radius: 4px;
&.errors {
border-color: @priceColor;
}
&.active,
&:focus {
border-color: @xtxColor;
}
}
.code {
position: absolute;
right: 1px;
top: 1px;
width: 80px;
height: 48px;
text-align: center;
line-height: 48px;
font-size: 14px;
background: #f5f5f5;
color: #666;
cursor: pointer;
}
}
.error {
line-height: 28px;
color: @priceColor;
i {
font-size: 16px;
margin: 0 1px 0 8px;
}
}
}
.submit {
display: block;
width: 320px;
height: 50px;
color: #fff;
font-size: 16px;
text-align: center;
background: @xtxColor;
border-radius: 4px;
&.disabled {
background: #cfcdcd;
}
}
}