Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Majeed's avatar

How to pass props array into a child component array in Vue

I'm try to pass a parent props array in my child component array. my child component is a modal Here,is my props value

props:{
 userdata:{
        type:[Array,Object],
        required:true,
      },
}

and my child component array

data(){
      return{
       mutableRoles:[],    
      }

i want to pass my userdata array into my mutableRoles array

0 likes
5 replies
realrandyallen's avatar

Just make mutableRoles a prop in your child component and pass it that way

// parent component
<child-component :mutable-roles="userdata"></child-component>

// child-component
...
    props: ['mutableRoles']
...
Majeed's avatar

@REALRANDYALLEN - no, i want to copy into another array. just like this:

this.mutableRoles=this.userdata
Majeed's avatar

@REALRANDYALLEN - that's working, but when i select new value it's shows a warning: [Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders.

realrandyallen's avatar

@MAJEED - Yes, I should have had you do this slightly different, but easy fix:

// parent component
<child-component :mutable-roles="roles"></child-component> //reference your data property rather than your prop

export default {
    props: {
        userdata: {
            type: [Array, Object],
            required: true
        }
    },

    data() {
        return {
            roles: this.userdata // data property named 'roles', or name it whatever you want, just be sure to also change above where you add your child-component
        }
    }
}

// child-component
...
    props: ['mutableRoles']
...

Please or to participate in this conversation.