vux修改css樣式的2種辦法


  最近手上有個移動端的項目。前端UI框架是選擇的VUX。但是在使用的時候經常會發現框架自帶的組件樣式和我們要求的不一致。經常需要手動覆蓋樣式。這里記錄下我們使用的2種方法。

我們以XHeader組件為例。XHeader組件默認為藏青色。
enter image description here
enter image description here

全局方式

找到build目錄下的webpack.base.conf在最后加入一下2行

const themeConfig={
  name: 'less-theme',
  path: 'src/assets/less/theme.less'
};
module.exports = vuxLoader.merge(webpackConfig, {
  plugins:['vux-ui', themeConfig]
});

注意path的路徑
enter image description here
然后我們在theme.less里面增加

/**
* Header
*/
@header-background-color: #3cc51f;
@header-title-color: black;

enter image description here

局部方式

  由於有時候我們一個界面有多個組件。樣式都不一致的時候。全局方式就不適用了。所以我們需要采用局部的方式。同樣還是XHeader我們這次需要把他們在同個界面把顏色修改成2種顏色可以使用/deep/ 或者>>>這里方式來修改。
enter image description here

<template>
  <div class="wrap">
    <x-header class="">XX銀行<a slot="right"></a>
    </x-header>
    <div class="wrap1">
      <x-header class="">XX銀行<a slot="right"></a>
      </x-header>
    </div>
    <toast v-model="isToast" type="text" position="middle" :text="toastTxt" width="auto"></toast>
  </div>
</template>

<style scoped>
  .wrap /deep/ .vux-header {
    background-color: #3cc51f;
  }
  .wrap1 >>> .vux-header {
    background-color: red;
  }
</style>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM