Read other people's code, generated ajax parameters can be this. Attribute? this question? If yes or no, then why?

I"m looking at the code written by others, and there"s one thing I don"t understand. The original picture:
!

:3:

May.18,2022
The

parameter can be written here, because the closure problem is not involved. It is recommended that the landlord take a look at the principle and practice of the closure and the pointing problem of this to understand the role of this writing.


in ordinary functions, this points to itself, and the arrow function this points to the wrapper. If you want to use this directly in the callback function of ajax, you need to write the function as an arrow function:

$ajax.xxx(params, res => {
    this.xxx; //  this  vm 
})

  1. first of all, the method under vue executes the Function-sharpbind method for you by default, so the this under the method is fixed to the instance of Vue, so you can use this to get the properties under the instance.
  2. you have written an ordinary function in the then of promise. The this point inside the ordinary function is related to the execution environment of the function. It is executed in the promise chain, and the point of this is certainly not a Vue instance
  3. .
  4. if you want to use this instead of _ this to save references, just use the arrow function, because the arrow function does not have this, and this is used in the body of the function using the outer this, that is, the Vue instance.

let _ this = this;
this code is actually to get the this of the context.
if you want to use this directly, use the arrow function.
can refer to this blog

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-1eb2db7-4714d.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-1eb2db7-4714d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?