JS获取Promise对象里面的值问题

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

JS获取Promise对象里面的值问题

赛尔号-   2023-02-03 我要评论

JS获取Promise对象里面的值

1、以下代码返回值为:

	const res = getTaskItems({});
    if (res.code === 0) {
    	this.taskItem = res.data;
    }

2、使用一下代码即可获取data里面的值

  getTaskItems({}).then(res => {
      console.log(res.data);
    })

获取Promise{<pending>}的值

问题

我使用如下代码

let lyric = getLyric(this.$store.state.songId);
console.log(lyric)

获取到的结果:

如果直接console.log(lyric.data),会输出undefined

解决

let lyric = getLyric(this.$store.state.songId);
let a = lyric.then((res)=>{
    console.log(res.data)
});

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持。

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们