BeforeChange, learn to check the usage instructions of switch components in the iView API documentation when you encounter problems

  • PS: Before-change is a property of the switch, which can be prevented by returning a Promise. Before-change =”handleBeforeChange” // No arguments, So how do you switch the incoming parameters?
handleBeforeChange(){
   return new Promise(resolve =>{
 	 resolve()
   })
}
Copy the code

Render with the render function, depending on how to get the parameters passed in, you need to get the parameters before clicking on the click event, so you want to trigger the mousedown event (which takes precedence over the click event), Define variables currWid,currStatus to accept parameters as follows:

<i-switch value={row.status} onInput={(val) => { row.status = val; }} nativeOnMousedown={() => { vm.handelOnMounseDown(row.wid, row.status); }} trueValue="1" falseValue="0" beforeChange={vm.handleBeforeChange} > <span slot="open"> Open </ SPAN > <span Slot ="close"> Close </span> </i-switch> //i-switch on or off switch data handelOnMounseDown(wid, status) {this.currWid = wid; this.currStatus = status === "1" ? false : true; } ## i-switch on or off return the state of the switch when the promise object is returned. HandleBeforeChange () {return new Promise(async (resolve) => {const [err, Res] = await switchApi({// call apiWid: this.currwid, status: this.currstatus,}); if (err) { this.$Message.error(err.errmsg); return; } this.$message. success(" operation succeeded "); resolve(); }); },Copy the code

Well, a simple record, if you can help friends with the same problem, is also a harvest ha ~~ every day to learn diudiu, do an interesting rookie ~~, if you think you can, feel free to like it, a small action is to give small rookie affirmation yo ~~