扩展 Vuetify 组件

编程入门 行业动态 更新时间:2024-10-10 01:20:34
本文介绍了扩展 Vuetify 组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

扩展vue(vuetify)组件的最佳方式是什么v-select.

What is the best way to extend vue (vuetify) component v-select.

例如,我想创建 <v-city></v-city> 组件,该组件使用最少的 props<扩展 v-select/code>,异步项目加载并选择项目之一.

For example, I want to create <v-city></v-city> component that extends v-select with minimal props, async items loaded and one of items selected.

我已经开始使用 template

<template>
    <v-select
        :items="items"
        v-model="item"
        required
        return-object
        autocomplete
        item-text="name"
        item-value="id"
    ></v-select>
</template>

脚本

<script>
    export default {
        name: 'v-city',
        data()
        {
            return {
                item: null,
                items: [],
                disabled: true
            };
        },
        created()
        {
            this.$http({
                method: 'GET',
                url: '/api.cities'
            })
                .then(response => this.items = response.data)
                .catch(console.warn);
        },
        methods: {},
        watch: {
            item(nv)
            {
                this.$emit('update', nv.id);
            }
        }
    };
</script>

和用法:<v-city @update="local.city = arguments[0]"></v-city>

我要存档的是:<v-city v-model="local.city" label="Select city"></v-city>

推荐答案

回答我自己的问题:使用 v-bind="this.$attrs" 来应用所有父"属性在子组件上.还可以使用 this.$listeners.input 更改值.可能不是理想的唯一解决方案,但它有效.

To answer on my own question: use v-bind="this.$attrs" to get all "parent" attributes applied on child component. Also use this.$listeners.input to change value. Probably not ideal and only solution, but it works.

这篇关于扩展 Vuetify 组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-27 01:10:23,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:组件   Vuetify

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!