The problem of this in ts

in the ts file, it is supposed to intercept the error, and then pop up a message, but calling this here will report an error.

// 
axiosTokenInstance.interceptors.response.use((response: any) => {
  if (response.data.statusCode !== 0) {
    this.$Message.error("haha");
  } else {
    return response.data;
  }
},
  (error) => {
    if (error.response) {
      const { message } = error.response.data;
      return Promise.reject(new Error(message));
    }
    return Promise.reject(error);
  }
);

then modified the code

const that = this;

// 
axiosTokenInstance.interceptors.response.use((response: any) => {
  if (response.data.statusCode !== 0) {
    that.$Message.error("haha");
  } else {
    return response.data;
  }
},
  (error) => {
    if (error.response) {
      const { message } = error.response.data;
      return Promise.reject(new Error(message));
    }
    return Promise.reject(error);
  }
);
After the

modification, the outer this is marked red again [ts] "this" implicitly has the type "any" because it has no type comments. [2683] who can tell us how to solve the problem? /

Jan.12,2022

ts provides / / @ ts-ignore to mark the user the code to ignore the check

but pay attention to the object reference of this, which is different from the this reference of function () {} and () = > {}. Since @ ts-ignore is used, you must judge and debug the code correctly before submitting the code, and @ ts-ignore should not be abused, otherwise you will lose the original intention of ts.

https://www.tslang.cn/docs/ha.


  

Hello, landlord, have you solved it?
I have encountered a similar problem. If it is solved, can you tell me how to do it?

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