Skip to content
On this page

基础用法

可以借助全局配置组件,来进行样式覆盖

[default]默认按钮
[plain]简约按钮
[round]圆角按钮
[dashed]虚线按钮
<template>
  <b-config-provider
    :theme="{
      binColorPrimary: '#722ed1',
      binColorSuccess: '#13c2c2',
      binColorWarning: '#e14c19',
      binColorDanger: '#d42a87'
    }"
  >
    <div>
      <div>[default]默认按钮</div>
      <div class="demo-button">
        <b-button type="primary">Primary</b-button>
        <b-button type="success">Success</b-button>
        <b-button type="warning">Warning</b-button>
        <b-button type="danger">Danger</b-button>
      </div>
      <div>[plain]简约按钮</div>
      <div class="demo-button">
        <b-button type="primary" plain>Primary</b-button>
        <b-button type="success" plain>Success</b-button>
        <b-button type="warning" plain>Warning</b-button>
        <b-button type="danger" plain>Danger</b-button>
      </div>
      <div>[round]圆角按钮</div>
      <div class="demo-button">
        <b-button type="primary" round>Primary</b-button>
        <b-button type="success" round>Success</b-button>
        <b-button type="warning" round>Warning</b-button>
        <b-button type="danger" round>Danger</b-button>
      </div>
      <div>[dashed]虚线按钮</div>
      <div class="demo-button">
        <b-button type="primary" dashed>Primary</b-button>
        <b-button type="success" dashed>Success</b-button>
        <b-button type="warning" dashed>Warning</b-button>
        <b-button type="danger" dashed>Danger</b-button>
      </div>
    </div>
  </b-config-provider>
</template>

<style scoped>
.demo-button {
  margin: 8px 0;
}
</style>
<template>
  <b-config-provider
    :theme="{
      binColorPrimary: '#722ed1',
      binColorSuccess: '#13c2c2',
      binColorWarning: '#e14c19',
      binColorDanger: '#d42a87'
    }"
  >
    <div>
      <div>[default]默认按钮</div>
      <div class="demo-button">
        <b-button type="primary">Primary</b-button>
        <b-button type="success">Success</b-button>
        <b-button type="warning">Warning</b-button>
        <b-button type="danger">Danger</b-button>
      </div>
      <div>[plain]简约按钮</div>
      <div class="demo-button">
        <b-button type="primary" plain>Primary</b-button>
        <b-button type="success" plain>Success</b-button>
        <b-button type="warning" plain>Warning</b-button>
        <b-button type="danger" plain>Danger</b-button>
      </div>
      <div>[round]圆角按钮</div>
      <div class="demo-button">
        <b-button type="primary" round>Primary</b-button>
        <b-button type="success" round>Success</b-button>
        <b-button type="warning" round>Warning</b-button>
        <b-button type="danger" round>Danger</b-button>
      </div>
      <div>[dashed]虚线按钮</div>
      <div class="demo-button">
        <b-button type="primary" dashed>Primary</b-button>
        <b-button type="success" dashed>Success</b-button>
        <b-button type="warning" dashed>Warning</b-button>
        <b-button type="danger" dashed>Danger</b-button>
      </div>
    </div>
  </b-config-provider>
</template>

<style scoped>
.demo-button {
  margin: 8px 0;
}
</style>

抽象容器

可以使用抽象标签来注入,这里会默认注入到html ,进行全局覆盖(谨慎使用,避免冲突和覆盖,一般用于全局配置主题使用)

<template>
  <b-config-provider abstract :theme="config">
    <b-button type="primary" @click="setGlobal">
      点击应用(应用后主颜色会变更,会影响全局)
    </b-button>
  </b-config-provider>
</template>

<script setup>
import { ref } from 'vue'

const config = ref({})

function setGlobal() {
  config.value = { binColorPrimary: '#00c181' }
}
</script>
<template>
  <b-config-provider abstract :theme="config">
    <b-button type="primary" @click="setGlobal">
      点击应用(应用后主颜色会变更,会影响全局)
    </b-button>
  </b-config-provider>
</template>

<script setup>
import { ref } from 'vue'

const config = ref({})

function setGlobal() {
  config.value = { binColorPrimary: '#00c181' }
}
</script>