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

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b2bb44-4d155.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b2bb44-4d155.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?