Vue.js 在组件中设置道具值时如何更新道具值

Vue.js 在组件中设置道具值时如何更新道具值,vue.js,vuejs2,vue-component,Vue.js,Vuejs2,Vue Component,在Vue组件中,当立即设置“道具”时,需要更新集合以包含其他属性 组成部分是: Vue.component('blog-post', { props: ['dataArray'] //needs to update this value when it sets. ... }) 您可以通过从子组件中显示值在父组件中进行更改,如: Vue.component('blog-post', { props: ['dataArray'] //needs to updat

在Vue组件中,当立即设置“道具”时,需要更新集合以包含其他属性

组成部分是:

Vue.component('blog-post', {
  props: ['dataArray']   //needs to update this value when it sets.
...
})

您可以通过从子组件中显示值在父组件中进行更改,如:

   Vue.component('blog-post', {
        props: ['dataArray']   //needs to update this value when it sets.
      ,
     methods:{
     update(val){
        this.$emit('updatedata',val)
     } 
     }
  })
在父组件中,按如下方式使用它:

    <blog-post @updatedata="updatedataArray"><blog-post>

    ...
      methods:{
         updatedataArray(val){
         //update your data array   
         }
      }

...
方法:{
updatedataArray(val){
//更新您的数据数组
}
}

在这里,我不能对父组件进行任何更改。此外,“dataArray”同一对象需要更新。您无法更新子组件内的道具,或者您可以将该dataArray更改为数据对象属性。在这种情况下,您可以轻松更新它。您可以使用watch属性查看道具中的更改。我似乎不清楚这个问题,到目前为止您尝试了什么?还有