axios.get('/api/ServerInfo/GetQueryTypedTSSST' ).then(function(res){ this.options=res.data }).catch(function (error) { console.log(error); });
可是在組件中已經聲明瞭
data() { return { options:[],
在 then
的內部不能使用Vue的實例化的this
, 因爲在內部 this
沒有被綁定。
可以使用ES6的箭頭函數
axios.get('/api/ServerInfo/GetQueryTypedTSSST' ).then((res)=>{ this.options=res.data }).catch(function (error) { console.log(error); });
或者在axios外面定義that
var that=this axios.get('/api/ServerInfo/GetQueryTypedTSSST' ).then(function(res){ this.options=res.data }).catch(function (error) { console.log(error); });