vue scss变量和mixins全局引用 和 scss变量在js中引用

vue scss变量全局共享

首先要装两个插件

"style-resources-loader": "^1.3.3",
"vue-cli-plugin-style-resources-loader": "^0.1.4",

如果装完报错,建议用npm再装一次

文件_variables.scss

/* Variables */

// Base color
$blue:#324157;
$light-blue:#3A71A8;
$red:#C03639;
$pink: #E65D6E;
$green: #30B08F;
$tiffany: #4AB7BD;
$yellow:#FEC171;
$panGreen: #30B08F;

// Sidebar
$sideBarWidth: 210px;
$subMenuBg:#1f2d3d;
$subMenuHover:#001528;
$subMenuActiveText:#f4f4f5;
$menuBg:#304156;
$menuText:#bfcbd9;
$menuActiveText:#409EFF; // Also see settings.sidebarTextTheme

// Login page
$lightGray: #eee;
$darkGray:#889aa4;
$loginBg: #2d3a4b;
$loginCursorColor: #fff;

// The :export directive is the magic sauce for webpack
// https://mattferderer.com/use-sass-variables-in-typescript-and-javascript
:export {
  menuBg: $menuBg;
  menuText: $menuText;
  menuActiveText: $menuActiveText;
}

第一步
配置文件 vue.config.js

const path = require('path')
module.exports = {
	pluginOptions: {
	    'style-resources-loader': {
	      preProcessor: 'scss',
	      patterns: [
	        // 路径根据具体需求更改
	        path.resolve(__dirname, 'src/styles/_variables.scss'),
	        path.resolve(__dirname, 'src/styles/_mixins.scss')
	      ]
	    }
	  },
}

如果不配置,起服务的时候会报找不到style-resources-loader的错
完成后就可以直接在其他文件使用scss定义好的变量了

scss变量在js中引用

_variables.scss 中 把要被引用的变量导出

$menuBg:#304156;
$menuText:#bfcbd9;
$menuActiveText:#409EFF; // Also see settings.sidebarTextTheme

:export {
  menuBg: $menuBg;
  menuText: $menuText;
  menuActiveText: $menuActiveText;
}

在这里插入图片描述

在这里插入图片描述

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值