嵌套对象上的vuejs v-bind.sync do(t更新父母

发布于 2025-02-01 18:53:47 字数 1514 浏览 0 评论 0原文

大家好,我正在建立一个巨大的形式,应该用嵌套对象上传一个巨大的对象。 对于更方便的源管理,我决定将我的表格分开在子组件中,并通过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技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

往事风中埋 2025-02-08 18:53:47

我终于使用Vuex商店和MapState功能进行了解决方法

I finally went for a workaround with vuex store and mapState function

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文