我正在尝试运行一个函数,它需要一些从挂载方法中得到的数据。现在我试着用
computed
创建函数,但不幸的是,对于这种情况,之前计算的运行
mounted
所以我没有函数所需的数据。以下是我的工作内容:
computed: {
league_id () {
return parseInt(this.$route.params.id)
},
current_user_has_team: function() {
debugger;
}
},
mounted () {
const params = {};
axios.get('/api/v1/leagues/' +this.$route.params.id, {
params,
headers: {
Authorization: "Bearer "+localStorage.getItem('token')
}
}).then(response => {
debugger;
this.league = response.data.league
this.current_user_teams = response.data.league
}).catch(error => {
this.$router.push('/not_found')
this.$store.commit("FLASH_MESSAGE", {
message: "League not found",
show: true,
styleClass: "error",
timeOut: 4000
})
})
}
如你所见,我有
debugger
在被调用的计算函数中
current_user_has_team
功能。但我需要从AXIOS调用中得到的数据。现在调试器中没有数据。我应该使用什么回调来利用网络请求返回的数据?谢谢您!