Vue2 defines global color styles

  1. 安装less、less-loader、style-resources-loader 和 vue-cli-plugin-style-resources-loader

  2. Create a global color file, here is the baseColor.less fileinsert image description here

  3. Configure it in the vue.config.js file, and the path is the path of the global color file just created, that is, the path of the baseColor.less file. Note that the path here cannot be abbreviated, such as @/assets
    insert image description here

    const path = require('path')
    pluginOptions: {
          
          
        'style-resources-loader': {
          
          
          preProcessor: 'less',
          patterns: [path.resolve(__dirname, './src/assets/style/baseColor.less')]
        }
     }
    
  4. Finally, you can use it directly where you need itinsert image description here

Guess you like

Origin blog.csdn.net/qq_37344867/article/details/127072414