【问题标题】:Adding functionality to Vuetify component, mass pass in props向 Vuetify 组件添加功能,大量传入 props
【发布时间】:2019-05-03 11:34:10
【问题描述】:

我希望能够将道具发送到 Vuetify 组件,而无需在我的组件中分配每个道具,有没有一种方法可以批量传递所有道具?

下面是我目前正在做的,但是有很多道具'。

我试图简单地扩展 VSelect 组件,但是这会返回多个似乎不容易修复的错误!

<template>
    <v-flex xs12 sm6>
        <v-select v-model="selected" :items="data"
                  :label="label"
                  :multiple="multiple"
                  :chips="chips"
                  :hint="hint"
                  :persistent-hint="persistentHint"
                  :counter="counter"
                  :dark="dark"
        ></v-select>
    </v-flex>
</template>
<script>
    export default {
        props: {
            label: {
                default: false,
                type: String|Boolean
            },
            multiple: {
                default: true,
                type: Boolean
            },
            chips: {
                default: true,
                type: Boolean
            },
            hint: {
                default: '',
                type: String|Boolean
            },
            persistentHint: {
                default: this.hint !== '' || this.hint !== false,
                type: String|Boolean
            },
            counter: {
                default: false,
                type: Number|Boolean
            },
            dark: {
                default: false,
                type: Boolean
            },
        },
        data: function() {
            return {
                selected: [ ],
                data: [
                    'test', 'test2', 'test3'
                ]
            }
        }
    }
</script>

【问题讨论】:

    标签: vue.js


    【解决方案1】:

    您可以将道具作为对象传递:

    <v-select
      v-model="selected" 
      :items="data"
      v-bind="$props"
    ></v-select>
    

    [https://vuejs.org/v2/guide/components-props.html#Passing-the-Properties-of-an-Object]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-26
      • 2017-11-19
      • 2012-08-08
      相关资源
      最近更新 更多