Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/471.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Vue:v型不';不要使用动态组件_Javascript_Vue.js_Vuejs2_Vue Component - Fatal编程技术网

Javascript Vue:v型不';不要使用动态组件

Javascript Vue:v型不';不要使用动态组件,javascript,vue.js,vuejs2,vue-component,Javascript,Vue.js,Vuejs2,Vue Component,例如: foo的值在输入期间保持不变 我一直在努力解决这个问题。我检查了很多问题和线索,但没有一个对我有帮助 HTML不起作用: <component :is="field.component" :key="key" :name="field.name" v-for="(field, key) in integration_data"

例如:

foo
的值在输入期间保持不变

我一直在努力解决这个问题。我检查了很多问题和线索,但没有一个对我有帮助

HTML不起作用:

            <component
                :is="field.component"
                :key="key"
                :name="field.name"
                v-for="(field, key) in integration_data"
                v-model="field.value"
            >
            </component>
            <input
                :key="key"
                :name="field.name"
                v-for="(field, key) in integration_data"
                v-model="field.value"
            >
export default {
init: function (init_data) {

    return new Vue({
        data: {
            integration_data: [
              {name: 'field_name0', component: 'input', value: ''},
              {name: 'field_name0', component: 'input', value: ''},
            ]
        },
    });
}
}

v-model
与您可能要做的事情无关。看起来您正在尝试动态插入组件。这正是
:is
所做的。现在,要将数据传递到组件,您应该使用
道具

例如:

您的Vue实例:

const vm = new Vue({
  el: '#app',
  data: {
    exampleValue: 'This value will be passed to the example component'
  }
})
注册组件:

Vue.component('example-component', {
  // declare the props
  props: ['value'],
  template: '<span>{{ value}}</span>'
})
Vue.component('example-component'{
//申报道具
道具:['value'],
模板:“{value}}”
})
然后像这样使用它:

<example-component :value="exampleValue"></example-component>

或:


您不能将
input
用作一种组件类型,而期望它是本机输入元素<代码>:is必须命名组件(如果需要,可以包含输入)

那么你必须明白:

因此,对于要与
v-model
一起工作的组件,它应该(可以是 在2.2.0+中配置:

  • 接受
    属性
  • 使用新值发出
    输入
    事件
综上所述,您可以将
v-model
:is
一起使用

newvue({
el:“#应用程序”,
数据:{
集成数据:[{
名称:“一”,
组成部分:“一”,
值:“ok”
}]
},
组成部分:{
一:{
道具:['name','value'],
模板:“{name}}和”,
计算:{
proxyValue:{
get(){返回this.value;},
set(newValue){this.$emit('input',newValue);}
}
}
}
}
});

{{field.value}}

谢谢您的回复。我希望不仅仅是将数据传递给组件,而是允许组件对其进行更改。关于Vue的github问题,有人告诉我们,对于本机元素,这是不可能的。谢谢!我现在明白了。
<component :is="'example-component'" :value="exampleValue"></component>