首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >论道具风格在服饰中的传承

论道具风格在服饰中的传承
EN

Stack Overflow用户
提问于 2019-10-11 17:50:23
回答 1查看 256关注 0票数 1

如何将样式支柱(如在Vuetify中的<v-btn outlined>My Button</v-btn>中概述的支柱)应用到多个标记,而不需要将其设置为每个事件。例如,对于在

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

创建一个使“大纲”(在本例中是这样)的CSS类显然是可行的,但有点违背了道具的目的。

或者,是否可以在某个地方设置默认道具,这样就不需要声明它们了?

EN

回答 1

Stack Overflow用户

发布于 2019-10-11 18:53:18

代码语言:javascript
复制
// 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 (实际上是帕格,但这并不重要)

代码语言:javascript
复制
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

输出

代码语言:javascript
复制
wrap:false
wrap:true
wrap:true
wrap:false

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

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

https://stackoverflow.com/questions/58346255

复制
相关文章

相似问题

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