javascript - Vuetify,如何设置默认 Prop

标签 javascript vue.js vuetify.js

我已经开始使用 Vuetify,但我正在寻找一种方法来修改某些组件上的默认 Prop 。

有办法吗?

即而不是不断地写:

<v-layout wrap></v-layout>

我可以让布局的默认 wrap 属性为 true 吗?

最佳答案

类似的内容,但如果您是 vue.js 的新手,请注意您必须阅读一些内容:

相关文档:vue mixin , vue extends

js

// 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

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

关于javascript - Vuetify,如何设置默认 Prop ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54791902/

相关文章:

javascript - 将 md-switch 转换为 md-select

javascript - create-react-app max_old_space_size 不起作用

javascript - 使用 vue 的多个路由器

javascript - 如何在 VueJS 中将复选框值绑定(bind)到 null 对象?

css - 如何让 v-col 变成可滚动的?

javascript - Google Apps 脚本返回数组值并在 javascript 函数中使用它们

javascript - JS : Regex in replace

javascript - 从匿名函数访问 Vue 方法

javascript - 在 v-data-table 中使用标题槽时添加空标题行

drag-and-drop - Vuetify TreeView + 拖放