vue全局引入scss(mixin)
我們在寫VUE的時候,會使用scss,也會做一些通用樣式,方便使用,在寫好的通用樣式的時候,每次都要單文件導(dǎo)入,剛開始寫的時候,感覺還好,后面工程量大了后,就顯得麻煩,那么本文就全局導(dǎo)入scss樣式!
1、mixin.scss
// 顏色定義規(guī)范
$color-background : #FFFFFF;
$color-background-d : rgba(0, 0, 0, 0.3);
$color-highlight-background : #333;
$color-dialog-background : #666;
$color-theme : #ffcd32;
$color-theme-d : rgba(255, 205, 49, 0.5);
$color-sub-theme : #d93f30;
$color-text-d : rgba(255, 255, 255, 0.3);
$color-text-l : rgba(255, 255, 255, 0.5);
$color-text-ll : rgba(255, 255, 255, 0.8);
$font-gray : #999;
//字體定義規(guī)范
$font-size-small-s : 10px;
$font-size-small : 12px;
$font-size-medium : 14px;
$font-size-medium-x : 16px;
$font-size-large : 18px;
$font-size-large-x : 22px;
$font-weight : 600;
body,html{
//background: rgb(239, 242, 249);
}
//背景圖片 100%
@mixin bkgMaxSize($url) {
background-image: url($url);
background-repeat: no-repeat;
background-size: 100% 100%;
}
@mixin font-setting-group($font-size,$font-family,$font-weight,$color,$line-height){
font-size: $font-size;
font-family: $font-family;
font-weight: $font-weight;
color: $color;
line-height: $line-height;
}
//邊框圓角
@mixin borderRadius($radius) {
-webkit-border-radius: $radius;
-moz-border-radius: $radius;
-ms-border-radius: $radius;
-o-border-radius: $radius;
border-radius: $radius;
}
//定位上下左右居中
@mixin positionCenter {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
//定位上下居中
@mixin ct {
position: absolute;
top: 50%;
transform: translateY(-50%);
}
//定位左右居中
@mixin cl {
position: absolute;
left: 50%;
transform: translateX(-50%);
}
//定位全屏
@mixin allcover {
position: absolute;
top: 0;
right: 0;
}
//相對定位
@mixin my-absolute($left, $top,$z) {
position: absolute;
z-index: $z;
margin-left: $left;
margin-top: $top;
}
//寬高-不同
@mixin widthHeightN($width, $height){
width: $width;
height: $height;
}
//寬高-相同
@mixin widthHeightY($number){
width: $number;
height: $number;
}
//字體大小,顏色
@mixin sizeColor($size, $color){
font-size: $size;
color: $color;
}
//flex布局
@mixin center_none{
display: flex;
justify-content: center;
align-items: center;
}
@mixin center_center{
display: flex;
justify-content: center;
align-items: center;
}
@mixin flex-start_center{
display: flex;
justify-content: flex-start;
align-items: center;
}
@mixin space-between_center{
display: flex;
justify-content: space-between;
align-items: center;
}
@mixin space-around_center{
display: flex;
justify-content: space-around;
align-items: center;
}
@mixin flex-end_center{
display: flex;
justify-content: flex-end;
align-items: center;
}
@mixin wrap_flex-start{
display: flex;
flex-wrap:wrap;
align-content:flex-start;
}
@mixin flex-start_column{
display: flex;
justify-content: flex-start;
flex-direction: column;
}
@mixin none_center_column{
display: flex;
align-items: center;
flex-direction: column;
}
@mixin center_center_column{
display: flex;
align-items: center;
justify-content: flex-start;
flex-direction: column;
}
這個文件就是全局封裝好的scss
2、單文件使用


3、全局掛載
3.1 導(dǎo)入依賴
npm install sass-resources-loader
添加配置:
vue.config.js文件中添加如下代碼
module.exports = {
outputDir: 'mbb',/*輸出目錄*/
publicPath: '/',/*訪問前綴*/
lintOnSave: false,//關(guān)閉Eslint檢測
chainWebpack: config => {
const oneOfsMap = config.module.rule('scss').oneOfs.store
oneOfsMap.forEach(item => {
item
.use('sass-resources-loader')
.loader('sass-resources-loader')
.options({
// Provide path to the file with resources
// 要公用的scss的路徑
resources: 'src/assets/stylus/mixin.scss'
})
.end()
})
}
}
chainWebpack塊中的
3.2 重啟項目


到此這篇關(guān)于 vue全局引入scss(mixin)的文章就介紹到這了,更多相關(guān) vue全局引入scss內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue計算屬性無法監(jiān)聽到數(shù)組內(nèi)部變化的解決方案
今天小編就為大家分享一篇vue計算屬性無法監(jiān)聽到數(shù)組內(nèi)部變化的解決方案,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-11-11
vue3?+?async-validator實現(xiàn)表單驗證的示例代碼
表單驗證可以有效的過濾不合格的數(shù)據(jù),減少服務(wù)器的開銷,并提升用戶的使用體驗,今天我們使用?vue3?來做一個表單驗證的例子,需要的朋友跟隨小編一起學(xué)習(xí)下吧2022-06-06
vue路由導(dǎo)航守衛(wèi)和請求攔截以及基于node的token認證的方法
這篇文章主要介紹了vue路由導(dǎo)航守衛(wèi)和請求攔截以及基于node的token認證的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-04-04
el-input限制輸入正整數(shù)的兩種實現(xiàn)方式
el-input框是Element UI庫中的一個輸入框組件,用于接收用戶的輸入,這篇文章主要介紹了el-input限制輸入正整數(shù),需要的朋友可以參考下2024-02-02

