DEV Community

Discussion on: Multiple v-model for the rest of us

Collapse
 
sjoerd82 profile image
Sjoerd82

One odd thing I just came across when using this on arrays (and I imagine on objects as well). Normally I would in a component, in the created()-phase, wait on the $nextTick to set an isLoaded variable to true, this way I'm sure everything is populated and ready, however, the variables set via this multiple v-model take a long time to initialize, and aren't ready yet on $nextTick.

I found no other way to wait for the first time the watcher got triggered on the array. This feels like it's the wrong way around:

models: [
    { data: "arrMyArray", event: "models:arrMyArray" },
],

watch: {
    arrMyArray(newVal) {
        if (!this.isLoaded) {
            this.isLoaded = true
        } else {
            this.$emit('models:arrMyArray',newVal)
        }
    },
},
Enter fullscreen mode Exit fullscreen mode