less配置全局公用变量文件,如何以变量的形式在html中 引入


一、在vue.config.js文件中

const path = require('path')

const vars = path.resolve(__dirname, './src/assets/css/common.less') 

module.exports = {
    css: {
        loaderOptions: {
            less: {
                globalVars: {
                    hack: `true; @import "${vars}"`,
                },
            },
        },
    },
}

 二、以变量的形式引入

1、在公共的less文件中导出

@menuBg:red;

:export {
    menuBg: @menuBg;
}

2.1、在man.js全局引入

import commonColor from './assets/css/common.less'

Vue.prototype.commonColor = commonColor

3、使用

//进度条自定义颜色
<el-progress :percentage="20" :color="commonColor.menuBg" />

4、局部引入(使用同上)

import commonColor from '@/assets/css/common.less'

//计算属性
 computed: {
        commonColor() {
            return commonColor
        },
  },

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM