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

平台网站开发sem培训学校

平台网站开发,sem培训学校,里水网站设计,小企业广告投放平台axios请求 安装 npm install axios全局自定义请求 集中处理设置 集体通用请求 example const instance axios.create({baseURL: https://some-domain.com/api/,timeout: 1000,headers: {X-Custom-Header: foobar} });请求前 请求后 拦截器 // 添加请求拦截器 axios.in…

axios请求

安装

npm install axios

全局自定义请求

集中处理设置 集体通用请求

example

const instance = axios.create({baseURL: 'https://some-domain.com/api/',timeout: 1000,headers: {'X-Custom-Header': 'foobar'}
});

请求前

请求后

拦截器

// 添加请求拦截器
axios.interceptors.request.use(function (config) {// 在发送请求之前做些什么return config;}, function (error) {// 对请求错误做些什么return Promise.reject(error);});// 添加响应拦截器
axios.interceptors.response.use(function (response) {// 2xx 范围内的状态码都会触发该函数。// 对响应数据做点什么return response;}, function (error) {// 超出 2xx 范围的状态码都会触发该函数。// 对响应错误做点什么return Promise.reject(error);});

前后端交互

@umijs/openai插件

可以由后端kf4j文档 自动生成前端代码

npm i --save-dev @umijs/openapi

在根目录添加配置文件

import { generateService } from '@umijs/openapi'generateService({requestLibPath: "import request from '@/request'",schemaPath: 'http://localhost:8123/api/v2/api-docs',serversPath: './src',
})

pack.json设置

//  what;
//  自己添加openapi服务 设置要执行哪些代码
//    使用 node 运行openapi.config.js js文件"openapi": "node openapi.config.js",

bug1 后端未启动

fetch openapi error: FetchError: request to http://localhost:8123/api/v2/api-docs failed, reason: at ClientRequest.<anonymous> (D:\project\pioneak-picture-frontend\node_modules\node-fetch\lib\index.js:1501:11)

bug2 axios基础网址设置错误

const myAxios = axios.create({baseURL: 'http://localhost:8123',timeout: 60000,withCredentials: true,
});

全局状态管理

某一个信息多个页面共享数据

Pinia更新与共享

import { defineStore } from "pinia";
import { ref } from "vue";export const useLoginUserStore = defineStore("loginUser", () => {const loginUser = ref<any>({userName: "未登录",});async function fetchLoginUser() {// todo 由于后端还没提供接口,暂时注释// const res = await getCurrentUser();// if (res.data.code === 0 && res.data.data) {//   loginUser.value = res.data.data;// }/*what:测试用户登录loginUser常量 设置对象内容 3s后设置app.vue 中 使用 LoginUserStore.fetchLoginUser() 设置loginUser value 在vue动态响应 <div v-if="loginUserStore.loginUser.id">判断到了id*/setTimeout(() =>{loginUser.value = {userName: "测试用户", id: 1}},3000)}function setLoginUser(newLoginUser: any) {loginUser.value = newLoginUser;}return { loginUser, setLoginUser, fetchLoginUser };
});

使用状态全局

const LoginUserStore = useLoginUserStore()
LoginUserStore.fetchLoginUser()

在组件中使用状态全局对象与对象信息

<div v-if="loginUserStore.loginUser.id">{{loginUserStore.loginUser.userName ?? '无名'}}</div><div v-else><a-button type="primary" href="/user/login">登录</a-button></div>
const loginUserStore = useLoginUserStore()
http://www.dtcms.com/wzjs/379614.html

相关文章:

  • 网站建设价格更先进的seo服务
  • 北京赛车手机网站建设黑帽seo论坛
  • 西安市建设干部学校网站珠海网站建设优化
  • 网站开发文章营销和销售的区别在哪里
  • 自己电脑做局域网网站服务器seo综合查询国产
  • 怎么给网站做备案常用的网络营销工具有哪些
  • 个人淘客网站备案故事性营销软文
  • 购物网站建设报价做竞价推广这个工作怎么样
  • 深圳住房建设局网站申报百度识图查图片
  • 毕设做桌面端还是网站刷神马网站优化排名
  • 南宁好的网站建设公司怎么做自己的网站
  • 管理型网站建设费用明细河南网站推广那家好
  • 建立一个网站的流程cba最新积分榜
  • 单页网站 挣钱安全优化大师
  • 易优cms收费吗专业seo优化公司
  • 抚州做网站百度关键词优化大师
  • 微小旅行社能否做网站云速seo百度点击
  • 武汉哪些网站建设百度收录查询api
  • 网站设计与制作优点河北高端网站建设
  • 多语言多风格网站方案省好多会员app
  • 百度云服务器做php网站南平seo
  • 求做图的网站百度上做推广怎么收费
  • 铁建设文件在什么网站下载搜索引擎营销是什么意思
  • 品牌展示榜ui做的好的网站网页优化seo公司
  • 优惠券网站怎么做的淘宝的前100个关键词排名
  • wordpress 更改icon网站快速优化排名官网
  • 做网站网页免费推广引流平台
  • 哪个平台做网站好天天外链官网
  • 广州有哪些做网站专业的公司搜索引擎优化方法总结
  • 做网站软件图标是一个箭头的搜狗推广登录