同步思想-未捕获错误抛出

这段代码,乍一看没啥错误,

  1. async getEthBalance () {
  2. this.loading = true
  3. const eth = await CethAction.getEthBalance(this.account)
  4. this.$message.success('开始获取getEthBalance' + eth)
  5. this.loading = false
  6. },

结合交互,一旦函数抛错处理,loading可能一直为true

优化结果处理

  1. async mint () {
  2. this.loading = true
  3. try {
  4. await CethAction.mint(this.account, '0.1')
  5. } catch (error) {
  6. console.error(error)
  7. } finally {
  8. this.loading = false
  9. }
  10. },