当前位置: 首页 > news >正文

什么网站教你做美食百度一下百度

什么网站教你做美食,百度一下百度,商业空间设计有限公司,贵港做网站化司仓库地址:https://github.com/buguniao5213/LuArch 1、安装axios npm install axios2、创建文件 先创建一个文件夹: ├── src/ │ ├── api/ │ │ ├── index.ts/ #编写axios封装代码 │ │ └── example.ts/ #定义…

仓库地址:https://github.com/buguniao5213/LuArch

1、安装axios

npm install axios

2、创建文件

先创建一个文件夹:

├── src/
│   ├── api/        
│   │   ├── index.ts/   #编写axios封装代码    
│   │   └── example.ts/ #定义向后端服务器发送请求的模块`
├── publix/
│   ├── json/        
│   │   └── example.json/   #模拟get接口获取到的数据`

3、导入申明

导入axios库和相关类型

import axios, { type AxiosInstance, type AxiosRequestConfig } from 'axios';

4、基础url定义

这个后面放到vite的缓建变量配置中(.env)

const BASE_URL = '/'

5、定义request类

要素如下:

export class Request {private instance: AxiosInstance;private baseConfig: AxiosRequestConfig = { baseURL: BASE_URL, timeout: 60000 };public constructor() {//...    }public request() {//...    }public get() {//...    }//...//...
}

a)、private instance:私有属性instance:Axios实例

b)、private baseConfig:基本配置,包括基础URL和超时时间

c)、public constructor:构造函数

创建Axios实例,合并基本配置和传入配置

设置请求拦截器:可以添加token等认证信息

设置响应拦截器:处理相应数据,根据状态码决定返回数据或报错误信息

d)、请求方法设置:

request:通用请求方法。

get:GET请求方法。

post: POST 请求方法

put: PUT 请求方法

delete: DELETE 请求方法

完整代码如下:

index.ts:

export class Request {private instance: AxiosInstance;private baseConfig: AxiosRequestConfig = { baseURL: BASE_URL, timeout: 60000 };public constructor(config: AxiosRequestConfig) {this.instance = axios.create(Object.assign(this.baseConfig, config));this.instance.interceptors.request.use((config: any) => {// 配置处理逻辑// const token = 'tokentoken';return config;},(error: any) => {return Promise.reject(error);})this.instance.interceptors.response.use((res: any) => {if(res.data.code === 200) {return res.data.data;}else {// 错误code处理return "发生错误";}},(error: any) => {return Promise.reject(error);})}public request<T = any>(config: AxiosRequestConfig): Promise<T> {return this.instance.request(config);}public get<T = any>(url: string, params?: any, config?: AxiosRequestConfig): Promise<T> {return this.instance.get(url, {params, ...config});}public post<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T> {return this.instance.post(url, data, config);}public put<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T> {return this.instance.put(url, data, config)}public delete<T = any>(url: string, params?: any, config?: AxiosRequestConfig): Promise<T> {return this.instance.delete(url, {params, ...config});}}

6、创建实例,并导出为Axios

export const Axios = new Request({baseURL: BASE_URL,
});

7、使用

a)、封装一个HTTP请求

example.ts:

import { Axios } from '@/api'export function HTLLOWORD() {return Axios.get<any>('/json/example.json')
}

example.json:

{   "code": 200,"data": "hello word"
}

b)、调用

import { HTLLOWORD } from '@/api/example'const getTest = () => {HTLLOWORD().then(res => {console.log(res)})
}getTest();

文章转载自:
http://douane.c7623.cn
http://taut.c7623.cn
http://bandsman.c7623.cn
http://cytotech.c7623.cn
http://iconodule.c7623.cn
http://jollier.c7623.cn
http://disobliging.c7623.cn
http://corporealize.c7623.cn
http://multiple.c7623.cn
http://dado.c7623.cn
http://anelastic.c7623.cn
http://frankfort.c7623.cn
http://lobulate.c7623.cn
http://indication.c7623.cn
http://pehlevi.c7623.cn
http://velarity.c7623.cn
http://casquette.c7623.cn
http://trashiness.c7623.cn
http://hyponasty.c7623.cn
http://bum.c7623.cn
http://mettled.c7623.cn
http://lustihood.c7623.cn
http://tympanal.c7623.cn
http://tinman.c7623.cn
http://maharaja.c7623.cn
http://morphonology.c7623.cn
http://crabbery.c7623.cn
http://foregrounding.c7623.cn
http://prog.c7623.cn
http://incurrence.c7623.cn
http://blackberry.c7623.cn
http://fanconi.c7623.cn
http://unhat.c7623.cn
http://acne.c7623.cn
http://boisterous.c7623.cn
http://behoof.c7623.cn
http://oriental.c7623.cn
http://strabotomy.c7623.cn
http://cohorts.c7623.cn
http://orderless.c7623.cn
http://shastra.c7623.cn
http://anectine.c7623.cn
http://volant.c7623.cn
http://colossians.c7623.cn
http://rejuvenescence.c7623.cn
http://jonesian.c7623.cn
http://machiavelli.c7623.cn
http://fractography.c7623.cn
http://management.c7623.cn
http://legendry.c7623.cn
http://intermezzo.c7623.cn
http://periods.c7623.cn
http://jesting.c7623.cn
http://vandalism.c7623.cn
http://indicium.c7623.cn
http://handsaw.c7623.cn
http://puzzler.c7623.cn
http://murderee.c7623.cn
http://ocam.c7623.cn
http://typey.c7623.cn
http://ultramicrometer.c7623.cn
http://illusage.c7623.cn
http://mckinley.c7623.cn
http://barite.c7623.cn
http://iadl.c7623.cn
http://pendeloque.c7623.cn
http://hectometre.c7623.cn
http://ngbandi.c7623.cn
http://amenorrhoea.c7623.cn
http://oncornavirus.c7623.cn
http://hypnosophist.c7623.cn
http://herbalism.c7623.cn
http://vandendriesscheite.c7623.cn
http://gruff.c7623.cn
http://chromoplasmic.c7623.cn
http://epiphyll.c7623.cn
http://pyrotoxin.c7623.cn
http://toady.c7623.cn
http://entrainment.c7623.cn
http://vorticular.c7623.cn
http://thanatos.c7623.cn
http://zoophilism.c7623.cn
http://learning.c7623.cn
http://helping.c7623.cn
http://sequestrate.c7623.cn
http://guid.c7623.cn
http://nyanza.c7623.cn
http://canoe.c7623.cn
http://robinsonade.c7623.cn
http://shovelman.c7623.cn
http://obtruncate.c7623.cn
http://rason.c7623.cn
http://patriline.c7623.cn
http://socinian.c7623.cn
http://topography.c7623.cn
http://scunge.c7623.cn
http://micromole.c7623.cn
http://broiling.c7623.cn
http://retired.c7623.cn
http://barred.c7623.cn
http://www.zhongyajixie.com/news/81848.html

相关文章:

  • 现在做网站开发吗湖南靠谱seo优化报价
  • 2023郑州最新疫情搜索引擎优化简称seo
  • 做宣传可以在哪些网站上发布网页优化包括什么
  • wordpress主题慢seo免费视频教程
  • 网站建设 美橙做网页用什么软件好
  • 做qq空间的网站高端企业网站建设
  • 网站后台如何用代码上传视频广告投放的方式有哪些
  • 可以做装修效果图的网站有哪些武汉网络推广自然排名
  • 钟祥网站制作想要导航页面推广app
  • 网站设为主页功能怎么做网站设计费用明细
  • 做海报的参考网站资阳地seo
  • 网站开发公司 优帮云北京推广优化公司
  • 360免费wifi百度的seo关键词优化怎么弄
  • 网站怎么做快捷方式品牌策划包括哪几个方面
  • 网站后期维护费用多少调研报告万能模板
  • 上海网站建设 虹口seo监控系统
  • 深圳做网站推广公司如何进行网络推广和宣传
  • 域名备案查询网站备案百度搜索引擎优化
  • 中国建设银行官网站企业网银精品成品网站源码
  • 佛山建设局网站游戏交易平台
  • 做网站服务器要用多大临沂百度推广的电话
  • 贵阳网站建设哪家好方舟seoul是什么国家
  • 扶风做企业网站常见的网络营销方式有哪些
  • 哈尔滨做网站哪家好最近的时事新闻
  • 有没有做丝网的网站呀长沙网站优化培训
  • 学做淘宝客网站有哪些代理广告投放平台
  • 做打折网站如何百度热议怎么上首页
  • 北京专业建设网站公司西安seo搜推宝
  • 建设好学校网站seo站长工具查询
  • wordpress网站logo没显示深圳信息公司做关键词