The axios callback method failed, but it was successful to write the method into the callback

export default {

mounted() {
let para = {
  offset: 0,
  limit: 50000,
  exchangeNo: ""
};
var _this = this;
let commodityCode = [];
axios.post("/api/zd/futures/list", para)
  .then(function(response) {
    _this.total = response.data.total;
    for (var i = 0; i < response.data.rows.length; iPP) {
      commodityCode.push(response.data.rows[i].code)
    }
   _this.initlocalStore(_this.commodityCode)//localstorelocalstore

    _this.websocketsend(`shzd@1@${_this.storage.commodityCodeList}`) //websocket this.websock.send(agentData);
  })
  .catch(function(error) {
    console.log(error);
  });

}

Jun.16,2021

scope problem. This points to an error, not to what you think of vm, but to window, so you can't find initlocalStore

.

you can use the _ this or arrow function you defined above

Menu