Javascript VueJS从axios承诺中获得价值

Javascript VueJS从axios承诺中获得价值,javascript,vue.js,Javascript,Vue.js,我有这个密码 模板: 问题是,console.log按预期显示值,但在Vue渲染中,我得到了这个[object Promise]我想知道如何在解决承诺后显示值 感谢您的帮助您的代码是return axios,它是一个promise对象。如果要返回最终持续时间。您应该等待axios承诺并返回回复 async getDuration(id) { var duration = ''; const response = await axios.post('/api/v1/checkvideo'

我有这个密码

模板: 问题是,
console.log
按预期显示值,但在Vue渲染中,我得到了这个
[object Promise]
我想知道如何在解决承诺后显示值


感谢您的帮助

您的代码是return axios,它是一个promise对象。如果要返回最终持续时间。您应该等待axios承诺并返回回复

async getDuration(id) {
  var duration  = '';
  const response = await axios.post('/api/v1/checkvideo', {
    menu: id
  })
  return response.data[0].datas.duration;
}
编辑 由于
async
返回承诺,[对象承诺]将始终呈现在屏幕上。如果您想获取特定id的持续时间,我认为这样做是正确的

data() {
  return {
    id: null, // Maybe you should store the value of `id` here
    duration: null
  }
},
mounted() {
  this.getDuration(this.id)
},
methods: {
  async getDuration(id) {
    var duration  = '';
    const response = await axios.post('/api/v1/checkvideo', {
      menu: id
    })
    this.duration = response.data[0].datas.duration;
  }
}

我得到了同样的结果
async getDuration(id) {
  var duration  = '';
  const response = await axios.post('/api/v1/checkvideo', {
    menu: id
  })
  return response.data[0].datas.duration;
}
data() {
  return {
    id: null, // Maybe you should store the value of `id` here
    duration: null
  }
},
mounted() {
  this.getDuration(this.id)
},
methods: {
  async getDuration(id) {
    var duration  = '';
    const response = await axios.post('/api/v1/checkvideo', {
      menu: id
    })
    this.duration = response.data[0].datas.duration;
  }
}