VUE中 axios请求失败,TypeError: Cannot set property 'xxxxx' of undefined

vue前端开发中,使用axios请求后台报错,源码如下:

axios.get(url)
         .then(function (response) {
           this.storm = response.data.result;
           console.log(response.data)
         })
         .catch(function (error) {
           console.log(error)
         })

报错为:TypeError: Cannot set property ‘ storm’ of undefined

axios请求后article 发生变化,而我使用的是名字函数,this 关键字是匿名函数,vue实例,改成箭头函数就行,如下:

axios.get(url).then((response) => {
                       this.storm = response.data.result;
                        console.log(result);
                    })
                  .catch(function (error) {
           console.log(error)
         })

你可能感兴趣的:(VUE中 axios请求失败,TypeError: Cannot set property 'xxxxx' of undefined)