import axios from 'axios'

const service = axios.create({
  baseURL: process.env.VUE_APP_API, // 请求的接口
  timeout: 100000 // 请求超时时间
})

// 使用拦截器,定义全局请求头
service.interceptors.request.use(config => {
  // 在请求头中添加token
  config.headers.Authorization = window.localStorage.getItem("user")
  return config
})
// 设置 Vue.prototype.$http 为 axios 的别名:
Vue.prototype.$http=service
      this.$http({
        url: "url", 
        params: {
          bookNumber: this.booknum
        }
      })
        .then(res => {
        // 成功
        })
        .catch(err => {
        // 失败
        });

Logo

前往低代码交流专区

更多推荐