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:#3A71
·
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;
}
更多推荐
已为社区贡献2条内容
所有评论(0)