When passing parameters to the callback function in the parent component in the Vue sub-component, what if the callback function itself requires the parameter information of the parent component?

parent component declares function

methods: {
    edit(index, val) {
        console.log(index)
        console.log(val) //
    }
}

parent component calls child component to pass props

// editindex
<Child v-for="(item, index) in items" @editFn="edit(index)">

Sub-component trigger function

editHandler() {
    const value = "hello"
    this.$emit("editFn", value) //value
}
Jul.20,2021

< Child vmurfort = "(item, index) in items" @ editFn= "edit (index,arguments [0])" >. Thank Dajuan


it's a bit like whether a publish subscription integrates auto-snooping


1. The parent component can use .sync
2. You can v-on an event in the parent component to get the $emit of the child component


Menu