Add custom parameters to element UI components

CSDN Topic Challenge Phase 2
Participation Topic: Study Notes

When we use the elmentUI component, we use additional methods to add custom parameters to the component.

error code:

<el-input-number 
    v-model="num" 
    @change="numChange(myData)" 
    :min="1" 
    :max="10" 
    label="描述文字"
></el-input-number>

Here we use the el-input-number component, use the change event of this component, call the custom numChange method, and pass the myData parameter in the change method, but the myData cannot be obtained in the numChange method.

By querying the component method, it is found that there are two callback parameters of the change event: currentValue and oldValue.

 In the error code, the parameter obtained in each numChange is currentValue, so I thought, through the method of passing parameters, first call the change event, and then call the custom event in the callback function of the change event, and pass the custom parameters. can solve this problem.

The correct code is as follows:

<el-input-number 
    v-model="num" 
    @change="(currentValue,oldValue)=>numChange(currentValue,oldValue,myData)" 
    :min="1" 
    :max="10" 
    label="描述文字"
></el-input-number>

Guess you like

Origin blog.csdn.net/Hello_MrShu/article/details/127305034