【问题标题】:Inheriting prop style in Vuetify在 Vuetify 中继承 prop 样式
【发布时间】:2020-02-09 06:38:28
【问题描述】:

如何将样式属性(例如 Vuetify 中 <v-btn outlined>My Button</v-btn> 中的 outlined 属性)应用于多个标签,而无需将其设置为每个出现。例如对于 a 中的所有事件:

  • <v-app>
  • <template>
  • <v-card>

创建一个创建“轮廓”的 CSS 类(在这种情况下)显然可行,但有点违背了道具的目的。

或者,或者,可以在某处设置默认道具,因此不需要声明它们?

【问题讨论】:

    标签: vuetify.js


    【解决方案1】:
    // some already existing component, you need to get it somehow
    // most likely via `import <something-to-import>`
    let theExternalComponent = {
      props: { wrap: { default: false, type: Boolean } },
      template: "<li>wrap:{{wrap}}</li>"
    };
    // this simulates the global registration
    Vue.component("v-some-external-component", theExternalComponent);
    
    // -- lets start --
    
    // lets extend that component - and overwrite the default prop for wrap
    let extendedExternalwithOtherDefaults = {
      extends: theExternalComponent,
      mixins: [{ props: { wrap: { default: true } } }],
    };
    
    var app = new Vue({
      el: "#app",
      components: { "v-my-customized-component": extendedExternalwithOtherDefaults }
    });
    

    html(实际上是pug,但这并不重要)

    div(id="app")
      ul
        v-some-external-component
    
        v-some-external-component(wrap)
    
        v-my-customized-component
        // now defaults to wrap:true
    
        v-my-customized-component(:wrap="false") 
        // you can still set the wrap to false if required
    

    输出

    wrap:false
    wrap:true
    wrap:true
    wrap:false
    

    codepen:https://codepen.io/anon/pen/MLxbEW

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-24
      • 2011-03-16
      • 1970-01-01
      • 2015-09-07
      • 2016-04-22
      • 2017-04-03
      相关资源
      最近更新 更多