vue调用接口

刚入职,没用学过接口,vue等前段知识,现在对接口,这个是一张图,数据审核完成,根据后台提供的数据接口

在这里显示

说在里写接口,我很盟, 这是接口,我想知道怎么调用
那位大神讲一下接口,在那些调用,有没有视频,或讲解的,我在网上找得不一样啊

阅读 3.9k
1 个回答

getChannelById 这个方法里 return axios 是一个 promise 对象。建议你可以了解一下axios库promise
你可以
import {getChannelById} from 'api/xxx.js'
然后使用 async/await 或者 then(res => {}) 方式
比如:xxx.vue

methods:{
 async getData1(){
   try{
     const data = await getChannelById(params)
      // data 就是接口返回的数据
   }catch(err){
    console.log(err)
   }
 },
 // 或者
 getData2(){
     getChannelById(params).then(res => {
        // res 就是接口返回的数据
     }).catch(err => {
      console.log(err)
     })
 }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题