美文网首页
axios和promies 的使用

axios和promies 的使用

作者: Rascar | 来源:发表于2020-01-01 12:18 被阅读0次
//导入axios
import axios from 'axios'
//导出
export function request(config){//第一中方法
    return new Promies((reslove,resobjs)=>{
      //创建一个实例
      const instll = axios.create({
        baseRUL:'http://123.321/',//随便写的
      timeout:5000//请求的时间
    })

    instll(config).then(res=>{
          reslove(res)
    })
})

}


export function request(config){//第二中方法
      const instll = axios.create({
        baseRUL:'http://123.321/',//随便写的
      timeout:5000//请求的时间
    })
return install(config)

}

在 mine.js中使用
导入request.js文件
import  {request} from '路径'

//使用 第一中方法和第二中方法都是这样使用的
request({
url:'/home'
}).then(res=>{
  console.log(res)
})

相关文章

网友评论

      本文标题:axios和promies 的使用

      本文链接:https://www.haomeiwen.com/subject/iviwoctx.html