美文网首页
async await实现异步函数

async await实现异步函数

作者: 李昂李三光 | 来源:发表于2019-04-21 09:19 被阅读0次

在函数外部用async包裹着内容,然后用await在需要异步编译的函数前面声明,就能够达到异步编程的效果

mounted:async function(){
        this.$store.commit('hiddentHead',{
                        hiddentHead:true
                    })
        
            let res = await axios.get(api.detail+"?ids="+this.$route.query.id);
            console.log(res)
        
//      axios.get(api.detail+"?ids="+this.$route.query.id).then((res)=>{
//          console.log(res)
//      })
        
        
        }

async和await必须要成双,否则不起效

相关文章

网友评论

      本文标题:async await实现异步函数

      本文链接:https://www.haomeiwen.com/subject/bucpxqtx.html