简体   繁体   中英

v-model in dynamic component

I have a list of dynamic components that I render with a for loop.

<component
        v-for="component in components"
        :key="component.componentId"
        :is="component.type"
        :componentId="component.componentId">
</component>

One of the different component types is an element that contains an input field. I want to attach v-model to that input.

<input type="text" :name="name">

works but when I do

<input type="text" :name="name" v-model="value">

I get no errors but the component is not rendered. However

<input type="text" :name="name" :value="value" @input="setValue">

works, if used with an appropriate method setValue to update the value attribute.

How should I use v-model in the component?

Apparently dynamic type bindings don't work with v-model . Found a commit in the repository that confirms this. For some reason it doesn't give me the warning, even though process.env.NODE_ENV == undefined .

In the original question I stripped a lot of code to make it more readable but seems like I missed the important part.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM