Add multiple custom parameters to vue, react, third-party component events

Add multiple custom parameters to vue, react, third-party component events

In fact, vue and react are similar. The idea is to pass in the parameters of the original third-party component and return to the function that needs to customize multiple parameters. Please
refer to the official react: Insert picture description here
use es6's ... operator, you don't need to care how many original parameters it has, just add the parameters we need directly, such as the following sub, we click to get the value of item.

import React from 'react'

function EventParams(){
    let num=[1,2,3,4]
    let  listItems=num.map(item=>
        <li key={item} onClick={(...params)=>getNum(...params,item)}>{item}</li>
    )
    function getNum(...params){
        console.log(params[1])
    }
    return(
        <div>
            <ul>{listItems}</ul>
        </div>
    )
}
export default EventParams

Vue can also handle it like this

Guess you like

Origin blog.csdn.net/weixin_44494811/article/details/107224501