Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
969 views
in Technique[技术] by (71.8m points)

vue的created方法异步执行函数

问题描述

vuecreated方法中的函数执行顺序。

相关代码

 created() {
    this.fetchMinerTypesList()
    this.fetchCoinsList()
    this.fetchMiners()
    console.log(this.$route.query)
    this.fetchMinersList()
  },

你期待的结果是什么?实际看到的错误信息又是什么?

希望在this.fetchMinerTypesList()this.fetchCoinsList()两个函数执行完,再执行this.fetchMiners();最后执行this.fetchMinersList()


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

可以使用async/await

 async created() {
    await this.fetchMinerTypesList()
    await this.fetchCoinsList()
    await this.fetchMiners()
    await this.fetchMinersList()
  },

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...