Vue globally introduces scss (mixin)

Vue globally introduces scss (mixin)

When we write VUE, we will use scss and make some common styles for easy use. When writing the common styles, we have to import a single file each time. When we first start writing, it feels okay, but when the amount of work is large, it becomes troublesome. So this article will import the scss style globally!

1. mixin.scss

// Color definition specification $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;

//Font definition specification $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);

}

//Background image 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;

}

//Border radius @mixin borderRadius($radius) {

 

  -webkit-border-radius: $radius;

  -moz-border-radius: $radius;

  -ms-border-radius: $radius;

  -o-border-radius: $radius;

  border-radius: $radius;

}

//Positioning up, down, left, and right in the center @mixin positionCenter {

   position: absolute;

  top: 50%;

  left: 50%;

  transform: translate(-50%, -50%);

}

// Positioning up and down center @mixin ct {

  position: absolute;

  top: 50%;

  transform: translateY(-50%);

}

// Position left and right center @mixin cl {

  position: absolute;

  left: 50%;

  transform: translateX(-50%);

}

// Positioning full screen @mixin allcover {
 position: absolute;

  top: 0;

  right: 0;

}

//Relative positioning @mixin my-absolute($left, $top,$z) {


  position: absolute;

  z-index: $z;

  margin-left: $left;

  margin-top: $top;

}

//Different width and height @mixin widthHeightN($width, $height){


  width: $width;

  height: $height;

}

//Width and height - same @mixin widthHeightY($number){

 

  width: $number;

  height: $number;

}

//font size, color @mixin sizeColor($size, $color){

 

  font-size: $size;

  color: $color;

}

//flex layout @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;

}

This file is the globally encapsulated scss

2. Single file usage

3. Global Mount

3.1 Import Dependencies

npm install sass-resources-loader

Add configuration:

Add the following code to the vue.config.js file

module.exports = {

  outputDir: 'mbb',/*output directory*/

  publicPath: '/',/*Access prefix*/

  lintOnSave: false, // Turn off Eslint detection 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

            // The path of the scss to be shared resources: 'src/assets/stylus/mixin.scss'

          })

          .end()

    })

  }

}

chainWebpack chunk

3.2 Restart the project

This is the end of this article about vue's global introduction of scss (mixin). For more relevant vue's global introduction of scss content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • The whole process of installing and using SCSS in Vue2.x
  • How to implement the day and night mode switching function of Vue+scss
  • Steps to configure scss global variables in vue
  • Solve the problem that vue scoped scss is invalid
  • Steps to configure scss in vue2
  • Do you know how to use scss syntax in vue?

<<:  Solve the compatibility issue between MySQL 8.0 driver and Alibaba Druid version

>>:  Several ways to hide Html elements

Recommend

React new version life cycle hook function and usage detailed explanation

Compared with the old life cycle Three hooks are ...

How to handle spaces in CSS

1. Space rules Whitespace within HTML code is usu...

How to use SVG icons in WeChat applets

SVG has been widely used in recent years due to i...

JS implements WeChat's "shit bombing" function

Hello everyone, I am Qiufeng. Recently, WeChat ha...

js method to realize shopping cart calculation

This article example shares the specific code of ...

JavaScript to achieve full or reverse selection effect in form

This article shares the specific code of JavaScri...

Draw a heart with CSS3

Achieve resultsRequirements/Functionality: How to...

Introduction and installation of MySQL Shell

Table of contents 01 ReplicaSet Architecture 02 I...

Several common methods of CSS equal height layout

Equal height layout Refers to the layout of child...

Detailed explanation of mysql partition function and example analysis

First, what is database partitioning? I wrote an ...

mysql5.7 installation and configuration tutorial under Centos7.3

This article shares the MySQL 5.7 installation an...

Detailed tutorial on installing VirtualBox and Ubuntu 16.04 under Windows system

1. Software Introduction VirtualBox VirtualBox is...

Problems encountered when uploading images using axios in Vue

Table of contents What is FormData? A practical e...

JavaScript immediate execution function usage analysis

We know that in general, a function must be calle...