首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >定制bootstrap-vue组件

定制bootstrap-vue组件
EN

Stack Overflow用户
提问于 2018-07-27 04:34:27
回答 1查看 1.8K关注 0票数 0

用几个开发人员启动一个大型应用程序。使用webpack和bootstrap-vue。如何为(和其他组件)默认样式。换句话说,我可以默认:

代码语言:javascript
复制
<b-card>

等同于:

代码语言:javascript
复制
<b-card style="max-width: 40rem;" header-bg-variant="primary" header-text-variant="white">

以确保我们在整个应用程序中保持一致的外观。

EN

回答 1

Stack Overflow用户

发布于 2019-07-31 12:08:46

您可以使用SCSS/CSS覆盖来控制b卡布局,或者扩展/包装组件以默认所需的道具:

代码语言:javascript
复制
import { BCard } from 'bootstrap-vue'

export default {
  name 'MyCard',
   // Create as a functional component wrapper
  functional: true,
  // define our props (borrow from BCard)
  props: {
    ...BCard.props,
  },
  render(h, { props, data, children }) {
    return h(
      BCard,
      {
        props: {
          // Pass all props to BCard
          ...props,
          // Override the following prop defaults (if not provided)
          headerBgVariant: props.headerBgVariant || 'primary',
          headerTextVariant: props.headerBgVariant || 'white'
        },
        // Pass any additional (optional) attributes down
        attrs: data.attrs,
        // Set the style
        style: {
          // merge in any styles manually applied
          ...data.style,
          // Set the max-width if not explicitly set
          maxWidth: data.style.maxWidth || '40rem'
        }
      }
    )
  }
}

有关功能组件和呈现函数的更多信息,请参见https://vuejs.org/v2/guide/render-function.html#Functional-Components

要使用功能组件处理更复杂的数据合并,请查看https://github.com/alexsasharegan/vue-functional-data-merge

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51547122

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档