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

HTML table only displays the outer border of the table

I would like to ask a question. In Dreamweaver, I...

WeChat Mini Program Lottery Number Generator

This article shares the specific code of the WeCh...

Detailed process of installing logstash in Docker

Edit docker-compose.yml and add the following con...

Vue implements an example of pulling down and scrolling to load data

Table of contents Step 1: Installation Step 2: Ci...

How to modify mysql to allow remote connections

Regarding the issue of MySQL remote connection, w...

HTML displays ellipsis beyond the text... implemented through text-overflow

You need to apply CSS to div or span at the same t...

Five ways to traverse objects in javascript Example code

Table of contents Prepare Five weapons for…in Obj...

Vue implements tree table

This article example shares the specific code of ...

MySQL Error 1290 (HY000) Solution

I struggled with a problem for a long time and re...

Detailed explanation of how to reduce memory usage in MySql

Preface By default, MySQL will initialize a large...

How to store images in MySQL

1 Introduction When designing a database, it is i...

How to limit the input box to only input pure numbers in HTML

Limit input box to only pure numbers 1、onkeyup = ...

CSS inheritance method

Given a div with the following background image: ...

Docker Tutorial: Using Containers (Simple Example)

If you’re new to Docker, take a look at some of t...