https://www.cnblogs.com/lonhon/p/9887993.html
sass支持設置全局樣式變量,且變量可以計算
vue-cli2怎么設置全局變量網上已有很多方案,這里主要講下vue-cli3下怎么做
1 准備存放全局樣式變量的文件
_variable.scss,內容如下:
$theme-color: #3385ff;
2 配置loader
打開根目錄下 vue.config.js
寫入
module.exports = {
// ...
css: {
loaderOptions: {
sass: {
data: `
@import "@/assets/styles/_variable.scss";
`
}
}
}
}
3 使用全局變量
現在就可以在每個vue文件中直接使用全局變量了
<template></template>
<script></script>
<style lang="scss" scoped>
button{
color: $theme-color;
}
</style>