赞
踩
天梦星服务平台 (tmxkj.top)https://tmxkj.top/#/
npm install axios -g
- import axios from 'axios'
- let configuration = {
- url:"http://localhost:9090"
- }
- /**
- * 请求项目数据的请求体
- */
- async function http({ url, method, param }) {
- const httpUrl = configuration.url + url
- if (method === 'GET') {
- httpUrl + jsonToGetParams(param)
- }
- const { data } = await axios({
- url: httpUrl,
- method: method ? method : 'GET',
- data: method === 'GET' ? {} : param,
- headers: {
- 'content-type': 'application/json',
- token: localStorage.getItem('token') || ''
- }
- })
- return data
- }
- async function ask(e) {
- return http({
- url: e[0],
- method: e[1],
- param: e[2]
- })
- }
- export { ask }
-
- /**
- * GET参数转字符串
- * @param jsonObj
- * @returns {string}
- */
- function jsonToGetParams(jsonObj) {
- const params = Object.entries(jsonObj)
- .map(([key, value]) => `${key}=${value}`)
- .join('&')
- if (params.length >= 1) {
- return '?' + params
- } else {
- return params
- }
- }
- import {ask} from "../Api/requestBody";
-
- /**
- * 查询用户接口
- */
- export function getQueryUser(param){
- return ask(['/user/queryUser','GET',param]);
- }
- getQueryUserFun(){
- getQueryUser({
- id:"2222"
- }).then(res=>{
- console.log(res)
- })
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。