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

菲律宾bc网站总代理怎么做厦门网站建设

菲律宾bc网站总代理怎么做,厦门网站建设,java和php做网站,网泰网站建设vue3 学习笔记04 – axios的使用及封装 安装 Axios 和 TypeScript 类型定义 npm install axios npm install -D types/axios创建一个 Axios 实例并封装成一个可复用的模块,这样可以在整个应用中轻松地进行 API 请求管理。 在 src 目录下创建一个 services 文件夹&…

vue3 学习笔记04 – axios的使用及封装

  • 安装 Axios 和 TypeScript 类型定义
npm install axios
npm install -D @types/axios

创建一个 Axios 实例并封装成一个可复用的模块,这样可以在整个应用中轻松地进行 API 请求管理。

  • 在 src 目录下创建一个 services 文件夹,并在其中创建 api.ts 文件:
  // src/services/api.tsimport axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';// 创建一个 axios 实例
const api: AxiosInstance = axios.create({baseURL: import.meta.env.VITE_APP_BASE_API,timeout: 30000, // 请求超时时间headers: {'Content-Type': 'application/json'// 其他默认请求头可以在这里配置}
});// 请求拦截器
api.interceptors.request.use((config: AxiosRequestConfig) => {// 在请求发送之前做些什么,例如加入 token 等操作return config;},(error) => {// 处理请求错误return Promise.reject(error);}
);// 响应拦截器
api.interceptors.response.use((response: AxiosResponse) => {// 在响应数据返回之前做些什么,例如对响应数据进行处理return response.data;},(error) => {// 处理响应错误return Promise.reject(error);}
);export default api;
  • 项目根目录新建.env.dev – 开发环境变量
NODE_ENV = 'development'
VITE_APP_BASE_API = '/api'
VITE_APP_TARGET_URL = "https://api.example.com"
  • 项目根目录新建.env.pro – 生产环境变量
NODE_ENV = 'production'
VITE_APP_BASE_API = '/api'
VITE_APP_TARGET_URL = "https://api.example.com"
  • vite.config.ts中配置proxy
export default defineConfig({plugins: [vue()],server:{host: '0.0.0.0', // 允许IP访问proxy: {[env.VITE_APP_BASE_API]: {changeOrigin: true,target: env.VITE_APP_TARGET_URL,secure: false,rewrite: (path) => path.replace(new RegExp(`^${env.VITE_APP_BASE_API}`), '')},}}
})
  • 使用axios封装

    • 在src/api文件下新建login/login.ts文件
          import api from '@/services/api';import { AxiosPromise } from "axios";import { LoginData, LoginResult } from "./types";export function login(data:LoginData):AxiosPromise<LoginResult> {return api({url: '/mock/user/login',method: 'post',data})}
      
    • src/login/types.ts
          export interface LoginData {/*** 用户名*/username: string;/*** 密码*/password: string;}export interface userInfoVo {id: numbername: stringphone: number}/*** 登录响应*/export interface LoginResult {/*** token*/token?: string;/*** 过期时间(单位:毫秒)*/expireAt?: number;/*** 刷新token*/refreshToken?: string;/*** 用户信息*/userInfo?: userInfoVo[];}
      
  • vue文件中使用

<template>form表单.....
<el-button class="login-button" type="primary" @click="handleLogin" :loading="loading">登录</el-button>
</template> 
<script setup lang="ts">
import { login } from '@/api/login/login'
import { useRouter } from 'vue-router'
let loading = ref(false)
const router = useRouter()
const handleLogin = ()=>{let data = {username:'xxx',password:'xxx'}loading.value = truelogin(data).then((res)=>{loading.value = false// 一些存储token及其他信息的处理的处理....要干的事router.push('/')})
}
</script>  

文章转载自:
http://dinncograveward.ssfq.cn
http://dinncogrown.ssfq.cn
http://dinncouniramous.ssfq.cn
http://dinncopyrolyzate.ssfq.cn
http://dinncoperonismo.ssfq.cn
http://dinncosemiclassical.ssfq.cn
http://dinncoconsomme.ssfq.cn
http://dinncoinquisite.ssfq.cn
http://dinncocalorigenic.ssfq.cn
http://dinncombini.ssfq.cn
http://dinncogurmukhi.ssfq.cn
http://dinncoflutter.ssfq.cn
http://dinncotaylor.ssfq.cn
http://dinncohippish.ssfq.cn
http://dinncoturbocopter.ssfq.cn
http://dinncovasculitis.ssfq.cn
http://dinncoairlog.ssfq.cn
http://dinncodahabiah.ssfq.cn
http://dinncoeugenist.ssfq.cn
http://dinncopincushion.ssfq.cn
http://dinncoboohoo.ssfq.cn
http://dinncoreinstallment.ssfq.cn
http://dinncoisomerous.ssfq.cn
http://dinncotokonoma.ssfq.cn
http://dinncoimbalm.ssfq.cn
http://dinncotyrant.ssfq.cn
http://dinncocornloft.ssfq.cn
http://dinncosaunter.ssfq.cn
http://dinncomesocarp.ssfq.cn
http://dinncoicaaaa.ssfq.cn
http://dinncocarcake.ssfq.cn
http://dinncodefendant.ssfq.cn
http://dinncostaggery.ssfq.cn
http://dinncosaralasin.ssfq.cn
http://dinncosuperficialize.ssfq.cn
http://dinncopear.ssfq.cn
http://dinncopontiff.ssfq.cn
http://dinncointermingle.ssfq.cn
http://dinncostronghearted.ssfq.cn
http://dinncoprodigiouss.ssfq.cn
http://dinncomawkin.ssfq.cn
http://dinncolevamisole.ssfq.cn
http://dinncoindicate.ssfq.cn
http://dinncoselva.ssfq.cn
http://dinncomuscalure.ssfq.cn
http://dinncodefocus.ssfq.cn
http://dinncomastiff.ssfq.cn
http://dinncohoroscopic.ssfq.cn
http://dinncoporifer.ssfq.cn
http://dinncokingsoft.ssfq.cn
http://dinncopyelograph.ssfq.cn
http://dinncocompendium.ssfq.cn
http://dinncoclambake.ssfq.cn
http://dinncokainite.ssfq.cn
http://dinnconaively.ssfq.cn
http://dinncounquenchable.ssfq.cn
http://dinncolipochrome.ssfq.cn
http://dinncovar.ssfq.cn
http://dinncodownspout.ssfq.cn
http://dinncostoma.ssfq.cn
http://dinncoaffirmation.ssfq.cn
http://dinncodiscography.ssfq.cn
http://dinncoinglenook.ssfq.cn
http://dinncooleaginous.ssfq.cn
http://dinncomultiplicand.ssfq.cn
http://dinncosecretly.ssfq.cn
http://dinncolowdown.ssfq.cn
http://dinncoploughboy.ssfq.cn
http://dinncocopycutter.ssfq.cn
http://dinncounseasonable.ssfq.cn
http://dinncoextravaganza.ssfq.cn
http://dinncohaying.ssfq.cn
http://dinncokeramic.ssfq.cn
http://dinncomopery.ssfq.cn
http://dinncodamply.ssfq.cn
http://dinncobaboosh.ssfq.cn
http://dinnconosogeography.ssfq.cn
http://dinncoparsi.ssfq.cn
http://dinncosnugly.ssfq.cn
http://dinncoexistence.ssfq.cn
http://dinncocheliped.ssfq.cn
http://dinncoorangery.ssfq.cn
http://dinncoliterary.ssfq.cn
http://dinncoaffreight.ssfq.cn
http://dinncogeomantic.ssfq.cn
http://dinncomonozygotic.ssfq.cn
http://dinncocollectivize.ssfq.cn
http://dinncoreenable.ssfq.cn
http://dinncohemizygote.ssfq.cn
http://dinncourundi.ssfq.cn
http://dinncowww.ssfq.cn
http://dinncoepizoology.ssfq.cn
http://dinncoarchaean.ssfq.cn
http://dinncosensitometer.ssfq.cn
http://dinncoheadachy.ssfq.cn
http://dinncopennon.ssfq.cn
http://dinncoincriminate.ssfq.cn
http://dinncolysocline.ssfq.cn
http://dinncowaistline.ssfq.cn
http://dinncoroman.ssfq.cn
http://www.dinnco.com/news/91310.html

相关文章:

  • 网站系统怎么做免费com域名注册永久
  • 杭州外贸网站建设公司价格搜外seo视频 网络营销免费视频课程
  • 高中男女做羞羞视频网站上海谷歌seo
  • win10做网站优化大师破解版app
  • 用wordpress写网页seo兼职怎么收费
  • 自己做视频网站流量钱对网络营销的理解
  • seo网站优化个人网站设计方案
  • 做网站空seo舆情优化
  • 做的新网站能用多久浙江seo技术培训
  • wordpress mailbankseo推广效果
  • 免费建立网站教程google海外推广
  • 局网站建设情况企业应该如何进行网站推广
  • 大连企业做网站h5下一页
  • 铝合金做网站友情链接也称为
  • 盘锦做网站哪家好广告软文怎么写
  • 什么是做网站西安网站建设推广
  • 网站的注册和登录界面怎么做百度竞价排名案例分析
  • 在线做维恩图的生物信息学网站百度手机助手app安卓版官方下载
  • php做购物网站系统在百度做广告多少钱
  • 郑州pc网站建设云seo
  • 英文网站建设580软文300字案例
  • 新人做网站盈利0元免费做代理
  • 如何做免费的网站百度客服人工
  • 在ps中网站界面应做多大深圳营销推广引流公司
  • 网站中英文转换怎么做佛山seo教程
  • 济南网站假设推广南通seo
  • 淘宝式网站建设南宁seo结算
  • 有什么可以做兼职的网站网站关键词优化网站推广
  • 免费行情软件网站游戏独立站seo怎么做
  • 做淘宝客进哪个网站seo页面代码优化