In the VUE framework, if the subcomponent calls back multiple parameters through the $emit event

pseudo code is as follows:

  <div class="" v-for="(item,index) in arr" :key="index">
        < @change="dosomething"></>
  </div>
<script>
...
methods:{
dosomething:function(parame1)
{
    //  index    
          
}

</script>

this.$emit("change",this.);
If you write

@ change= "dosomething" in this way, parame1 gets the value passed by the child component. If @ change= "dosomething (index)", parame1 is the index passed by the parent component. If you cannot get the value passed by the child component

Thank you all in advance

Jun.10,2022

you can pass index to child components through props


:

1index

<child-compnent :index="index" @change="dosomething"/>

// index
this.$emit('change', {val: '', index: 'xxx'});

2. Store it on the data attribute, such as

<child-compnent :data-index="index" @change="dosomething"/>

// index
this.$emit('change', {val: '', index: index});

3, use arguments

<child-compnent @change="dosomething(arguments, index)"/>

// 
this.$emit('change', {val: ''});

// 
methods: {
    dosomething(obj, index) {
        const val = obj[0];
    }
}

4. Other methods are temporarily sufficient

Menu