Vue uses axios to get data, but cannot pass it to data

problem description

when using axios to get data, you can never assign values to variables defined in data

 data() {
    return {
        results: null
    }
},
mounted: function () {     
    var self = this;
    axios.get("/plot/")
      .then(function (response) {
          self.results = response.data
          console.log(self.results)
      })
    this.drawLine()
    console.log(self.results)
    
},

the environmental background of the problems and what methods you have tried

find the relevant problems on the Internet. You can get it by using the arrow function or if you specify this like this, but results is always null

.

related codes

/ / Please paste the code text below (do not replace the code with pictures)

what result do you expect? What is the error message actually seen?


Boss, network requests are asynchronous. The following console.log will be executed before your request is finished. So in fact, the assignment has been successful.

Menu