zixian

在使用Vue开发的过程中,通常会用到一些样式的全局变量,如果在每个组件中引入就太繁琐了,维护性也不好,因此全局引入是个不错的想法。下面以less为例,记录一下全局引入less变量的步骤:

1、首先安装依赖

在项目根目录的命令行工具里,执行以下命令。

npm i style-resources-loader vue-cli-plugin-style-resources-loader -D

2、配置vue.config.js文件

pluginOptions: {
      'style-resources-loader': {
        preProcessor: 'less',
        patterns: [path.resolve(__dirname, "src/common/less/variable.less")] // 引入全局样式变量
      }
}

   将上述代码添加到vue.config.js文件中。如图所示:

 

 

 运行项目,就大功告成了。

分类:

技术点:

相关文章:

  • 2021-04-29
  • 2019-08-26
  • 2021-10-26
  • 2021-07-09
  • 2021-10-14
  • 2021-11-21
  • 2021-11-17
  • 2021-10-20
猜你喜欢
  • 2020-07-18
  • 2021-12-23
  • 2021-10-08
  • 2021-11-25
  • 2021-11-23
  • 2021-12-03
相关资源
相似解决方案