1、在 less 文件中定义变量并将其导出为 js,CSS Module 有一个:export关键字,它在功能上等同于 ES6 的关键字export,即导出一个 js 对象。

// ./styles/variables.less

@themeColor: #00978d;

// 导出变量
:export {
    exportedKey: @themeColor; 
}

2、在需要使用的页面导入

<template>
  <div ></div>
</template>

<script>
import variables from './styles/variables.less';
export default {
  data() {
    return {
      variables,
    };
  },
  created() {
    console.log(this.variables, "variables");
  }
};
</script>

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-05
  • 2022-12-23
  • 2022-12-23
  • 2021-09-25
  • 2021-11-18
  • 2021-10-20
猜你喜欢
  • 2021-11-18
  • 2021-12-20
  • 2022-12-23
  • 2021-10-22
  • 2022-01-27
  • 2022-01-04
  • 2022-12-23
相关资源
相似解决方案