Arrow function in vue and ordinary function this point to

problem description:
encapsulates the callback when the axios method, getAxios () is successful
Why does the result appear in the following code

my idea:
1. () = > {} is equivalent to function () {} .bind (this)
2. In strict mode, the this in a function without a direct caller is undefined
himself vaguely aware of the reason, but not sure, hoping to get a clear answer.

  created () {
    this.getBannerList()
  },

  methods: {
    getBannerList () {
      getAxios("/bannerApi", (res) => {
        console.log(this)      //:VueComponent 
      })  
      
      getAxios("/bannerApi", function (res) {
        console.log(this)      //: undefined
      })
    }
  }
Apr.07,2021
The this of

ordinary function points to you can take a look at this blog post. I hope it will help you https://codeshelper.com/a/11.


Arrow function pointing to the outside, similar to the way bind (this), uses the vue,babel plug-in to replace it with ES5.


.

ordinary methods have this bindings inside

returns undefined because it is an asynchronous callback in strict mode this is undefined

The

arrow function is not bound to this and the this of the arrow function is to look up the scope chain and the this determines only at definition time that it is not run time

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