1. 安装依赖

    vue add style-resources-loader vue-cli-plugin-style-resources-loader -D

    1. 修改vue.config.js(没有的话在根目录创建) ```javascript // eslint-disable-next-line @typescript-eslint/no-var-requires const path = require(‘path’)

    module.exports = { publicPath: ‘’, pluginOptions: { ‘style-resources-loader’: { preProcessor: ‘less’, patterns: [ path.resolve(__dirname, ‘./src/less/theme.less’) ] } } }

    1. 3. 创建全局变量文件
    2. ![image.png](https://cdn.nlark.com/yuque/0/2021/png/2308212/1613872899676-9a4bb825-5f30-4102-8769-8a850bc5397f.png#align=left&display=inline&height=101&originHeight=101&originWidth=280&size=4479&status=done&style=none&width=280)
    3. 4. less文件定义变量
    4. ```less
    5. @color-primary:#409EFF;
    6. @color-success:#67C23A;
    7. @color-warning:#E6A23C;
    8. @color-danger:#F56C6C;
    9. @color-info:#909399;
    10. @color-text-primary:#303133;
    11. @color-text-regular:#606266;
    12. @color-text-secondary:#909399;
    13. @color-text-placeholder:#C0C4CC;
    14. @color-border-base:#DCDFE6;
    15. @color-border-light:#E4E7ED;
    16. @color-border-lighter:#EBEEF5;
    17. @color-border-extra-light:#F2F6FC;
    18. @color-background-white:#FFFFFF;
    19. @color-background-black:#000000;
    20. @color-background-base:#F5F7FA;
    1. 项目中使用变量
      1. <style lang="less">
      2. #app {
      3. color: @color-success;
      4. margin-top: 60px;
      5. }
      6. </style>