当前位置: 代码迷 >> 综合 >> vue-cli3设置sass/scss全局变量
  详细解决方案

vue-cli3设置sass/scss全局变量

热度:42   发布时间:2024-02-08 06:11:08.0

1 准备存放全局样式变量的文件

_variable.scss,内容如下:

$theme-color: #3385ff;

2 配置loader

打开根目录下 vue.config.js
写入

module.exports = {// ...css: {loaderOptions: {sass: {prependData: `@import "@/assets/styles/_variable.scss";`}}}
}

3 使用全局变量

现在就可以在每个vue文件中直接使用全局变量了

<template></template>
<script></script>
<style lang="scss" scoped>
button{
color: $theme-color;
}
</style>