1.安装axios,网上找方法

2.src->network->request.js并复制:

import axios from 'axios'
export function request(config) {
  const instance = axios.create({
    baseURL: "http://xxx.xxx.xxx.xxx:8085/api",
  })
  instance.interceptors.request.use(config => {
    if(config.method === "post"){
      config.data = JSON.stringify(config.data)
    } 
    return config
  },error => {
    console.log(error)
  })
  instance.interceptors.response.use(res =>{
    return res.data
  },error => {
    console.log(error)
  })
  return instance(config)
}
3.使用:src->network->register.js并复制:
import {request} from "./request";
export function register(mobile,password) {
  return request({
    url:'api/register',
    params:{
      mobile,
      password
    },
    method:'Post',
    headers: { 'Accept': 'application/json', 'Content-Type': 'application/x-www-form-urlencoded'},
  })
}
=====================
键值对参数:
export function logout(){
  var user = JSON.parse(localStorage.getItem('user'))
    return request({
     url:'/api/logout',
     data:{
      "userId":user.user.userId,
      },
     method:'Post',
     headers:{
        'post':{'Content-Type': 'application/json;charset=UTF-8'},
        'token':user.token
      }
   })
}
在使用页面:
import {register} from '../network/register'
 
registerBtn(){
   register(this.mobile,this.password).then(res=>{
          console.log(res)
    })
}
 

vue-axios设置公共的请求ip的更多相关文章

  1. [vue] [axios] 设置代理实现跨域时的纠错

    # 第一次做前端工程 # 记一个今天犯傻调查的问题 -------------------------------------------------------------------------- ...

  2. vue axios请求超时,设置重新请求的完美解决方法

    //在main.js设置全局的请求次数,请求的间隙 axios.defaults.retry = 4; axios.defaults.retryDelay = 1000; axios.intercep ...

  3. vue 使用axios 出现跨域请求的两种解决方法

    最近在使用vue axios发送请求,结果出现跨域问题,网上查了好多,发现有好几种结局方案. 1:服务器端设置跨域 header(“Access-Control-Allow-Origin:*”); h ...

  4. vue(24)网络请求模块axios使用

    什么是axios Axios 是一个基于 promise 的 HTTP 库,可以用在浏览器和 node.js 中. 主要的作用:axios主要是用于向后台发起请求的,还有在请求中做更多是可控功能. a ...

  5. 请求超时VUE axios重新再次请求

    //在main.js设置全局的请求次数,请求的间隙 axios.defaults.retry = 4; axios.defaults.retryDelay = 1000; axios.intercep ...

  6. vue axios 取消上次请求

    axios.defaults.timeout = 1000 * 5axios.defaults.baseURL = baseUrlvar CancelToken = axios.CancelToken ...

  7. VUE axios 发送 Form Data 格式数据请求

    axios 默认是 Payload 格式数据请求,但有时候后端接收参数要求必须是 Form Data 格式的,所以我们就得进行转换.Payload 和 Form Data 的主要设置是根据请求头的 C ...

  8. vue+vue-resource设置请求头(带上token)

    前言 有这样的一个需求,后台服务器要求把token放在请求头里面 嗯一般是通过data里面通过参数带过去的 第一种方法 全局改变: Vue.http.headers.common['token'] = ...

  9. axios设置请求头内容

    axios设置请求头中的Authorization 和 cookie 信息: GET请求 axios.get(urlString, { headers: { 'Authorization': 'Bea ...

  10. Vue+axios(interceptors) 实现http拦截 + router路由拦截 (双拦截)+ 请求自带loading效果

    axios interceptors 拦截器 //interceptors.js // vue axios配置 发起请求加载loading请求结束关闭loading // http request 请 ...

随机推荐

  1. 基础教材系列:编译原理——B站笔记

    一.编译器是什么 源程序→预处理器→经过预处理的源程序→编译器→汇编语言程序→汇编器→可重定位的机器代码→链接器/加载器→目标机器代码. 编译器的结构: 与源语言相关:字符流→词法分析器→词法单元流→ ...

  2. KingbaseES 原生XML系列三--XML数据查询函数

    KingbaseES 原生XML系列三--XML数据查询函数(EXTRACT,EXTRACTVALUE,EXISTSNODE,XPATH,XPATH_EXISTS,XMLEXISTS) XML的简单使 ...

  3. Collation 差异导致 KingbaseES 与 Oracle 查询结果不同

    问题引入 前端提了个问题,说是KingbaseES 返回的结果与 Oracle 返回的结果不一样.具体问题如下: oracle 执行结果:oracle 有结果返回. SQL> create ta ...

  4. async/await 与console(C#)

    问题: 上一篇async/await 致WPF卡死问题(https://www.cnblogs.com/stephen2023/p/17725159.html),介绍主线程阻塞,async/await ...

  5. Scala 函数闭包和柯里化

    1 package com.atguigu.function 2 3 object HighFunction { 4 def main(args: Array[String]): Unit = { 5 ...

  6. JS启动Windows上的exe

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. openGauss每日一练第四天

    openGauss 每日一练第四天 本文出处:https://www.modb.pro/db/193083 学习地址 https://www.modb.pro/course/133 学习目标 学习 o ...

  8. Kubernetes Pod配置:从基础到高级实战技巧

    本文深入探讨了Kubernetes Pod配置的实战技巧和常见易错点. 关注[TechLeadCloud],分享互联网架构.云服务技术的全维度知识.作者拥有10+年互联网服务架构.AI产品研发经验.团 ...

  9. Android Studio制作简单登录界面

    实现目标 应用线性布局设计登录界面,要求点击输入学号时弹出数字键盘界面,点击输入密码时弹出字母键盘,出现的文字.数字.尺寸等全部在values文件夹下相应.xml文件中设置好,使用时直接引用.当用户名 ...

  10. Web自动化实战:去哪儿网购票流程测试

    克隆源码 项目Github地址:https://github.com/gy-7/Web-automation-practice/tree/main/project1_qunar_booking_tic ...