嵌套对象上的vuejs v-bind.sync do(t更新父母
大家好,我正在建立一个巨大的形式,应该用嵌套对象上传一个巨大的对象。 对于更方便的源管理,我决定将我的表格分开在子组件中,并通过v-bind.sync指令进行双向更新,但我的子组件没有更新我的主要父对象 父母看起来像
parent
<template>
<ChildOne
v-bind.sync="assetData.CUSTOM_FAAS_PROPS"
/>
<ChildTwo
v-bind.sync="assetData.CUSTOM_PUBLICATION_PROPS"
/>
</template>
<script>
import ChildOne from '@/components/AssetForm/ChildOne.vue'
import ChildTwo from '@/components/AssetForm/ChildOTwo.vue'
export default {
components: {
ChildOne ,
ChildTwo
},
data: () => ({
assetData:{
CUSTOM_FAAS_PROPS:{
Description:{
en:'',
fr:''
},
Input:{
data:{
filekey:'',
extension:''
}
}
},
CUSTOM_PUBLICATION_PROPS:{}
}
})
}
</script>
。
<template>
<input
:value="Input.data.filekey"
@input="$emit('update:Input.data.filekey', $event), logresult($event)"
/>
</template>
<script>
export default {
props: {
Description:{
type: Object,
default () {
return {
en:'',
fr:''
}
}
},
Input:{
type: Object,
default () {
return {
data:{
filekey:'',
extension:''
}
}
}
}
},
methods: {
logresult($event){
console.log($event)
}
}
我的 我无法弄清楚如何将v-bind.sync用于嵌套对象
Hi everyone i'm building a huge form that should upload a huge Object with nested objects.
For more convenient source management i decided to split my form in child component and pass a v-bind.sync directive for bidirectional update but my child component isn't updating my main parent object
My parent looks like
parent.vue
<template>
<ChildOne
v-bind.sync="assetData.CUSTOM_FAAS_PROPS"
/>
<ChildTwo
v-bind.sync="assetData.CUSTOM_PUBLICATION_PROPS"
/>
</template>
<script>
import ChildOne from '@/components/AssetForm/ChildOne.vue'
import ChildTwo from '@/components/AssetForm/ChildOTwo.vue'
export default {
components: {
ChildOne ,
ChildTwo
},
data: () => ({
assetData:{
CUSTOM_FAAS_PROPS:{
Description:{
en:'',
fr:''
},
Input:{
data:{
filekey:'',
extension:''
}
}
},
CUSTOM_PUBLICATION_PROPS:{}
}
})
}
</script>
And my ChildOne.vue
<template>
<input
:value="Input.data.filekey"
@input="$emit('update:Input.data.filekey', $event), logresult($event)"
/>
</template>
<script>
export default {
props: {
Description:{
type: Object,
default () {
return {
en:'',
fr:''
}
}
},
Input:{
type: Object,
default () {
return {
data:{
filekey:'',
extension:''
}
}
}
}
},
methods: {
logresult($event){
console.log($event)
}
}
The log result print in console the content of my text input but the parent object is not updating.
I can't figure it out how to use v-bind.sync for nested object
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我终于使用Vuex商店和MapState功能进行了解决方法
I finally went for a workaround with vuex store and mapState function