如何将样式支柱(如在Vuetify中的<v-btn outlined>My Button</v-btn>中概述的支柱)应用到多个标记,而不需要将其设置为每个事件。例如,对于在
<v-app><template><v-card>创建一个使“大纲”(在本例中是这样)的CSS类显然是可行的,但有点违背了道具的目的。
或者,是否可以在某个地方设置默认道具,这样就不需要声明它们了?
发布于 2019-10-11 18:53:18
// 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 (实际上是帕格,但这并不重要)
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:falsehttps://stackoverflow.com/questions/58346255
复制相似问题