vue中axios获取到的值如何再次引用

回首过往如一梦 2017-10-20 11:51:49

<script>
export default {
name: '',
data() {
return {
user:'',
id:''
}
},
props: {},
computed: {},
methods: {
},
mounted () {
axios.get('/api/extensys/exten_action.php?act=get_userinfo&unionid=oaNquuJBYcTrl4EJOXYaINXN7xZo')
.then((response) => {
this.user = response.data.userInfo
this.id = response.data.loginResult.player.userid
// console.log(this.id)
// console.log(this.user)
})
axios.get('/api/extensys/action.php?act=get_levelinfo&userid=')
.then((response) => {
// this.user = response.data
console.log(response.data)
})
}
}
</script>


图中第一次axios获取到的 this.id = response.data.loginResult.player.userid userid的值作为第二次 axios.get('/api/extensys/action.php?act=get_levelinfo&userid=') userid中的参数
怎么把userid的值调用
...全文
1974 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Jo_cc 2020-03-06
  • 打赏
  • 举报
回复
牛逼牛逼牛逼
striker_c 2018-02-24
  • 打赏
  • 举报
回复
三层的话 需要在第二层再新建一个Promise???
  • 打赏
  • 举报
回复
谢谢 大佬
scscms太阳光 2017-10-20
  • 打赏
  • 举报
回复
mounted () {
    //============简单回调方法
    axios.get('/api/extensys/exten_action.php?act=get_userinfo&unionid=oaNquuJBYcTrl4EJOXYaINXN7xZo')
        .then((response) => {
            this.user = response.data.userInfo
            this.id = response.data.loginResult.player.userid
            axios.get('/api/extensys/action.php?act=get_levelinfo&userid='+this.id)
                .then((response) => {
                    console.log(response.data)
                })
        })
    //============或者使用Promise
    new Promise(function (resolve, reject) {
        axios.get('/api/extensys/exten_action.php?act=get_userinfo&unionid=oaNquuJBYcTrl4EJOXYaINXN7xZo')
            .then((response) => {
                this.user = response.data.userInfo
                this.id = response.data.loginResult.player.userid
                resolve(this.id);
            })
    }).then(function (id){
        axios.get('/api/extensys/action.php?act=get_levelinfo&userid='+id)
            .then((response) => {
                console.log(response.data)
            })
    })
}

87,901

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧