简体   繁体   English

动态组件中的v模型

[英]v-model in dynamic component

I have a list of dynamic components that I render with a for loop. 我有一个动态组件列表,我用for循环渲染。

<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. 我想将v-model附加到该输入。

<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. 如果与适当的方法setValue一起使用以更新value属性,则可以正常工作。

How should I use v-model in the component? 我应该如何在组件中使用v-model?

Apparently dynamic type bindings don't work with v-model . 显然,动态类型绑定不适用于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 . 出于某种原因,即使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. 在最初的问题中,我删除了大量代码以使其更具可读性,但似乎我错过了重要的部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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