vue cli3 定制vant主題色及設(shè)置全局less變量

vue-cli3定制vant主題色

  1. 安裝
    cnpm i babel-plugin-import -D

  2. babel.config.js

    module.exports = {
      presets: ['@vue/app'],
      plugins: [
        [
          'import',
          {
            libraryName: 'vant',
            libraryDirectory: 'es',
            style: name => `${name}/style/less`
          },
          'vant'
        ]
      ]
    }
    
  3. vue.config.js

    module.exports = {
      css: {
        loaderOptions: {
          less: {
            modifyVars: {
              red: '#d6426a',
              blue: '#7b8cce',
              orange: '#f08d49',
              'text-color': '#111'
            }
          }
        }
      }
    }
    
  4. 使用例子: demo.vue

    <template>
      <div class="demo">
        demo頁(yè)
        <div>
          <van-button type="default">默認(rèn)按鈕</van-button>
          <van-button type="primary">主要按鈕</van-button>
          <van-button type="info">信息按鈕</van-button>
          <van-button type="warning">警告按鈕</van-button>
          <van-button type="danger">危險(xiǎn)按鈕</van-button>
        </div>
        <div class="mt-30">
          <van-cell-group>
            <van-field v-model="value" placeholder="請(qǐng)輸入用戶名"/>
          </van-cell-group>
        </div>
      </div>
    </template> 
    
    <script>
        import { Button, Field, Cell, CellGroup } from 'vant'
        export default {
          components: {
            [Button.name]: Button,
            [Field.name]: Field,
            [Cell.name]: Cell,
            [CellGroup.name]: CellGroup
          },
          data() {
            return {
              value: ''
            }
          }
        }
    </script>
    <style lang="less" scoped>
    div {
        font-size: @fontSize1;
    }
    </style>
image.png

vue-cli3設(shè)置全局變量

  1. 安裝

    cnpm i style-resources-loader -S
    cnpm i vue-cli-plugin-style-resources-loader -S
    
  2. vue.config.js

    module.exports = {
      pluginOptions: {
        'style-resources-loader': {
          preProcessor: 'less',
          patterns: [path.resolve(__dirname, 'src/assets/css/mixin.less')]
        }
      }
    }
    
    
  3. minxin.less

    // 設(shè)置全局變量
    @minWidth: 1440px;
    @headerHeight: 80px;
    @primary: #0590ff;
    @info: #34bfa3;
    @warning: #f5a623;
    @danger: #f25151;
    @border: #ebedf2;
    @fontSize1: 14px;
    @fontSize2: 16px;
    
  4. 任意文件使用

    <style lang="less" scoped>
    div {
      font-size: @fontSize1;
    }
    </style>
    

github項(xiàng)目地址:https://github.com/SmaVivian/vue-cli3-h5-init.git

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容