1、安装less less-loader
yarn add less less-loader
2、安装style-resources-loader
yarn add style-resources-loader
3、安装vue-cli-plugin-style-resources-loader
yarn add vue-cli-plugin-style-resources-loader
4、配置vue.config.js
如果没有则新建vue.config.js
const path = require('path')
const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({transpileDependencies: true,pluginOptions: {"style-resources-loader": {preProcessor: "less",patterns: [path.resolve(__dirname,'./src/assets/css/base.less')]}}
})
4.1 base.less
@textColor: #99999;
@bgColor: #f2f3f4;
@lineHeight: 30px;
.textValue:{color: @textColor;line-height: @lineHeight;
}