我正在try 运行一个函数,该函数需要从挂载方法中获取一些数据.现在我try 使用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通话中得到的数据.现在我在调试器中没有数据.我应该使用什么样的回调,以便利用从网络请求返回的数据?非常感谢.