v-for

时间:2015-12-13 07:56:12

标签: vue.js

我有一个通过v-for生成的表单。

注意:我正在使用“@”来逃避刀片。

我的vue isstance有:

data: {
    form: {
        inputs: [{icon: "",  name="",  placeholder: "", type="",  value=""}]
    },
    owner: {first_name: "", last_name: "", cell_phone: "", email: ""}
}

我用以下内容生成表单:

<template v-for="input in form.inputs">
    <div style="margin-bottom: 25px" class="input-group">
        <span class="input-group-addon"><i class="glyphicon glyphicon-@{{input.icon}}"></i></span>
         <input id="login-@{{input.name}}" v-model="?????" type="@{{input.type}}" class="form-control" name="@{{input.name}}" placeholder="@{{input.placeholder}}">
    </div>
</template>

我想将每个输入绑定到各自的承包商属性。所以我希望v-models值为owner.first_name,owner.last_name,owner.cell_phone和owner。电子邮件。我希望我能做到:

 v-model="'owner' + @{{input.name}}"

但我明白了:

[Vue warn]: v-model="'owner' + {{input.name}}": attribute interpolation is not allowed in Vue.js directives and special attributes.
vue.js:1956 Error: Warning Stack Trace
    at warn (vue.js:1956)
    at Directive.bind (vue.js:4507)
    at Directive._bind (vue.js:8668)
    at linkAndCapture (vue.js:7367)
    at compositeLinkFn (vue.js:7345)
    at new Fragment (vue.js:5373)
    at FragmentFactory.create (vue.js:5575)
    at Directive.create (vue.js:5844)
    at Directive.diff (vue.js:5757)
    at Directive.update (vue.js:5692)

所有者属性对应于每个输入的input.name。

由于

应用程序说明:我正在尝试使用多个表单构建所有者。每个表单都是通过ajax请求生成的,该请求获取一个表单对象,该表单对象包含输入n和该表单的操作。

1 个答案:

答案 0 :(得分:17)

你可以试试这个:

v-model="owner[input.name]"
相关问题