Vue Cli3 配置alias以及如何使用scss


首先  npm install sass-loader node-sass --save

1、配置alias

在vue.config.js里:紅色部分

const path = require('path');

module.exports = {
  configureWebpack: { resolve: { alias: { '@': path.resolve(__dirname, 'src'),
        style: path.resolve(__dirname, 'src/style') } } },
  devServer: {
    port: 8081,
    proxy: {
      '/api': {
        target: 'http://localhost:8081',
        changeOrigin: true,
        pathRewrite: {
          '^/api': '/mock'
        }
      }
    }
  },
  css: {
    loaderOptions: {
      sass: {
        prependData: '@import "~@/style/_variable.scss";'
      }
    }
  }
};

2、使用scss以及如何使用全局變量

在src目錄下建立style文件夾,在style文件夾下建立_variables.scss

 

 _variables.scss:

$blue: #00a0dc;
$blackColor: #07111b;
$lightColor: #93999f;

// 背景全鋪
@mixin full_background {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: pink;
}

3、在組件中使用scss變量

 

 效果圖:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM