Vue考试专用

axios封装
rquest.js

import Cookies from "js-cookie";
import axios from "axios";
//axios的封装
const requests = axios.create({
    baseURL:'',
    timeout:30000
})

requests.interceptors.request.use((config)=>{
    if(Cookies.get('token')){
        //请求头添加字段
        config.headers.Token = Cookies.get('token')
    }
    return config;
})

requests.interceptors.response.use((res)=>{
    return res.data;
},(error)=>{
    console.log(error.message);
})


export default requests;

封装所有请求
index.js

//当前模块对所有接口进行统一管理
import requests from "./request";

//用户页面接口http://bg4ege.natappfree.cc

export const getUserList = (params) => requests({url:'/user/findAllUser',method:'get',params})
//登录
export const reqUserLogin = (data) => requests({url:'/admin/login',method:'post',data})
//提交密码申诉结果
export const reqPwdAgreeOrRefude = (data) => requests({url:'/appeal/appealAgreeOrRefuse',method:'post',data})
//获取仓库表单
export const reqFindAllBook = (params) => requests({url:'/order/findAllStores',method:'get',params})
export const reqCheckStatus = (params) => requests({url:'/book/modifyBook',method:'post',params})

//查看密码申诉
export const getPwdList = (params) => requests({url:'/appeal/findAppeal',method:'get',params})
//删除用户,传入学号
export const reqDeleteUser = (data) => requests({url:'/user/deleteUser',method:'post',data})
//更改用户信息
export const reqUpdateUser = (data) => requests({url:'/user/updateUser',method:'post',data})
//注册业务
// /user/addUser put User
export const reqUserAdd = (data) => requests({url:'/user/addUser',method:'put',data})
// /order/getAllOrder get 
export const reqOrderList = () => requests({url:'/order/getAllOrder',method:'get'})

///order/agreeOrRefuse Post type orderId userId
export const reqAgreeOrRefuse = (data) => requests({url:'/order/agreeOrRefuse ',method:"post",data})

vue.config.js

module.exports = {
  //关闭eslint校验工具
  lintOnSave: false,
  publicPath: "/",
  devServer: {
      proxy: {
          //配置跨域           
          '': {
              target: 'http://124.221.253.94', //这里后台的地址模拟的;应该填写你们真实的后台接口            
              changOrigin: true, //允许跨域            
              pathRewrite: {
                  /* 重写路径,当我们在浏览器中看到请求的地址   为:          http://localhost:8080/api/core/getData/userInfo 时           
                  实际上访问的地址是:
                  http://121.121.67.254:8185/core/getData/userInfo,因为重写了 /api           */
                  '': ''
              }
          },
      }
  },
}

请求样例

    //登录,设置token
    async userLogin({ commit }, data) {
        let result = await reqUserLogin(data)
        //服务器下发token
        if (result.code === 200) {
            commit("USERLOGIN", result.data.token);
            Cookie.set('token', result.data.token) // 第一个是cookie的名称,第二个是传入的值。然后再Cookie中生成了一条数据。
            return 'ok'
        } else {
            return Promise.reject(new Error('登录失败'))
        }
    },

reset.css

/* http://meyerweb.com/eric/tools/css/reset/ 
   v2.0 | 20110126
   License: none (public domain)
*/

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
	margin: 0;
	padding: 0;
	border: 0;
	font-size: 100%;
	font: inherit;
	vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
	display: block;
}
body {
	line-height: 1;
}
ol, ul {
	list-style: none;
}
blockquote, q {
	quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
	content: '';
	content: none;
}
table {
	border-collapse: collapse;
	border-spacing: 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值