A
A
alex_mappleart2020-10-17 15:15:46
JavaScript
alex_mappleart, 2020-10-17 15:15:46

How to pass v-model through component wrapper?

Hello. In my project, I use Vuetify, for convenience, I wrap all form elements with my component. I am interested in such a moment as the easiest way to connect the v-model of the parent and child components. Right now I'm using this design

export default {
                template: '<v-text-field v-model="model"></v-text-field>',
                props: ['value'],
                data(){
                        return {
                                model: '',
                        }
                },

                created(){
                        this.model = this.value;
                },

                mounted() {
                        this.model = this.value;
                },
                watch: {
                        value(){
                                this.model = this.value;
                        },
                        model(){
                                this.$emit('input', this.model)
                        },
                }
        }


Tell me, can this be done even easier?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex, 2020-10-17
@alex_mappleart

The documentation describes how to create such wrappers
https://v3.vuejs.org/guide/component-basics.html#u...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question