axios.get('api/getNewsList') .then((res) => { console.log(res) this.newsList = res.data.list })
使用老师的语法没问题,但是使用axiosapi提供的的语法
axios.get('api/getNewsList') .then(function (res) { console.log(res) this.newsList=res.data.list })
会报错 Cannot set property 'newsList' of undefined,网上查了查是this指向了全局,这里是不是只能用箭头函数