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

为什么要建立网站色盲测试图第五版

为什么要建立网站,色盲测试图第五版,如何关闭网络代理设置,网站无法显示网页内容文章目录 一、请求和传递参数1、get 请求2、post 请求3、axios 请求配置 二、axios 的二次封装1、配置拦截器2、发送请求 三、API 的解耦1、配置文件对应的请求2、获取请求的数据 四、总结 一、请求和传递参数 在 Vue 中,发送请求一般在 created 钩子中&#xff0c…

文章目录

  • 一、请求和传递参数
    • 1、get 请求
    • 2、post 请求
    • 3、axios 请求配置
  • 二、axios 的二次封装
    • 1、配置拦截器
    • 2、发送请求
  • 三、API 的解耦
    • 1、配置文件对应的请求
    • 2、获取请求的数据
  • 四、总结


一、请求和传递参数

在 Vue 中,发送请求一般在 created 钩子中,当然放在 mounted 钩子中也没问题。

以下请求的前提都是安装了 axios,并且 import axios from 'axios' 成功导入

Axios官网链接

1、get 请求

get 请求传参,在地址里面通过 ?xxx=123 的形式

  // Vue 环境中async created() {let res = await axios.get("http://testapi.xuexiluxian.cn/api/slider/getSliders?xxx=123");console.log(res);}

2、post 请求

post 请求传参,在第二个参数里面传递

  // Vue 环境中async created() {let res = await axios.post('http://testapi.xuexiluxian.cn/api/course/mostNew', {pageNum: 1,pageSize: 5})console.log(res);}

3、axios 请求配置

请求配置里面可以设置很多属性

  // Vue环境中async created() {let res = await axios({url: 'http://testapi.xuexiluxian.cn/api/course/mostNew',method: 'post', // 默认是 get 请求headers: {}, // 自定义请求头data: {  // post 请求,前端给后端传递的参数pageNum: 1,pageSize: 5}, params: {}, // get 请求,前端给后端传递的参数timeout: 0, // 请求超时responseType: 'json' // 返回的数据类型})console.log(res);}

二、axios 的二次封装

目的:方便统一管理

注意:先安装 axios 才可以使用,终端键入:npm i axios,之后回车安装它

1、配置拦截器

在 src 目录下新建 utils 文件夹,该文件夹下创建 request.js 文件

request.js 文件

  1. 首先创建 axios 对象
  2. 添加请求拦截器(前端给后端的参数)
  3. 添加响应拦截器(后端给前端的数据)
import axios from 'axios'// 创建 axios 对象
const instance = axios.create({baseURL: 'http://testapi.xuexiluxian.cn/api', // 根路径timeout: 2000 // 网络延时
})// 添加请求拦截器 => 前端给后端的参数【还没到后端响应】
instance.interceptors.request.use(function (config) {// 在发送请求之前做些什么return config;
}, function (error) {// 对请求错误做些什么return Promise.reject(error);
});// 添加响应拦截器 => 后端给前端的数据【后端返回给前端的东西】
instance.interceptors.response.use(function (response) {// 对响应数据做点什么return response;
}, function (error) {// 对响应错误做点什么return Promise.reject(error);
});// 最终返回的对象
export default instance

2、发送请求

在需要发请求的组件中,导入 request.js, 之后发送请求即可

App.vue 组件

  1. 在需要使用的组件中 导入 request
  2. 直接发送请求即可
<template><div id="app">发送请求</div>
</template><script>
import request from "./utils/request";
export default {name: "App",data() {return {};},created() {// get 请求request({url: "/course/category/getSecondCategorys",}).then((res) => {console.log(res);});// post 请求request({url: "/course/mostNew",method: "post",data: {pageNum: 1,pageSize: 5,},}).then((res) => {console.log(res);});}
}
</script>

三、API 的解耦

API 解耦的目的:为了同一个接口可以多次使用; 为了方便 api 请求统一管理

1、配置文件对应的请求

在 src 目录下新建 api 文件夹,该文件夹下创建 xxx.js 文件,配置对应请求

import { axios } from "@/utils/request"
import requestJpaas from "../../utils/geteway"
import serve from "./serve"
const { getData } = requestJpaas
// 服务
const prefix = "/jpaas-jiop-web-server"
const api = {// 获取用户信息getUserInfo: prefix + "/interface/buttjoint/jisbuttsuccess",
}export const yhzxAPI = {// 获取用户信息getUserInfo(params) {return axios({url: api.getUserInfo,method: "get",params})},// 网关接口queryList(appid, interface_id, params) {return getData({appid,interface_id,params})}
}

2、获取请求的数据

App.vue 组件

从文件定义的请求中导入对应函数
获取数据

<template><div></div>
</template><script>
import { yhzxAPI } from '@/api/yhzx/yhzx.js'export default {name: 'IndexView',data() {return {}},created() {this.getRecord()},mounted() {},methods: {getRecord() {let params = {title: document.title,address: encodeURIComponent(location.href),type: 'xxxxxx',}yhzxAPI.getUserInfo(params).then((result) => {if (result.code == 200 && result.success) {console.log('我的足迹添加成功!')} else {console.log('我的足迹添加失败或未登录!')}}).catch((err) => {console.log(err)})},}
}
</script><style scoped lang="less"></style>

四、总结

对 axios 的二次封装,在企业级项目中是 必须 要配置的。
因为经过封装的 axios,更容易使用和管理,并且可以 减少代码量,让 逻辑更清晰


文章转载自:
http://oropharynx.c7493.cn
http://demonstrable.c7493.cn
http://lucid.c7493.cn
http://chronicle.c7493.cn
http://sclerocorneal.c7493.cn
http://soarable.c7493.cn
http://mongeese.c7493.cn
http://ugliness.c7493.cn
http://diabolist.c7493.cn
http://transuranic.c7493.cn
http://papacy.c7493.cn
http://showerproof.c7493.cn
http://lymphoma.c7493.cn
http://turves.c7493.cn
http://pandybat.c7493.cn
http://wasteless.c7493.cn
http://ethnocide.c7493.cn
http://charmless.c7493.cn
http://irq.c7493.cn
http://chrp.c7493.cn
http://labyrinthine.c7493.cn
http://sarsenet.c7493.cn
http://levallois.c7493.cn
http://nucleinase.c7493.cn
http://sided.c7493.cn
http://scray.c7493.cn
http://railroad.c7493.cn
http://exhortatory.c7493.cn
http://enmesh.c7493.cn
http://pneuma.c7493.cn
http://soapsuds.c7493.cn
http://blousy.c7493.cn
http://geostrophic.c7493.cn
http://wordmongering.c7493.cn
http://nonclaim.c7493.cn
http://insalivate.c7493.cn
http://cytotrophy.c7493.cn
http://estrone.c7493.cn
http://robotism.c7493.cn
http://margaret.c7493.cn
http://draughts.c7493.cn
http://nephelite.c7493.cn
http://pics.c7493.cn
http://cheaply.c7493.cn
http://djakarta.c7493.cn
http://trochleae.c7493.cn
http://gelatin.c7493.cn
http://blowzy.c7493.cn
http://meridional.c7493.cn
http://parol.c7493.cn
http://throng.c7493.cn
http://gdmo.c7493.cn
http://placeman.c7493.cn
http://bimana.c7493.cn
http://tabefaction.c7493.cn
http://fishmonger.c7493.cn
http://pathophysiology.c7493.cn
http://hame.c7493.cn
http://clustering.c7493.cn
http://photocopier.c7493.cn
http://shadowgraph.c7493.cn
http://response.c7493.cn
http://siberian.c7493.cn
http://stamper.c7493.cn
http://tenebrionid.c7493.cn
http://impugnable.c7493.cn
http://chlorospinel.c7493.cn
http://ridger.c7493.cn
http://nominatival.c7493.cn
http://staple.c7493.cn
http://moneymonger.c7493.cn
http://doorhead.c7493.cn
http://recency.c7493.cn
http://pageantry.c7493.cn
http://brusque.c7493.cn
http://moderately.c7493.cn
http://scintillogram.c7493.cn
http://rosella.c7493.cn
http://sulfonal.c7493.cn
http://elide.c7493.cn
http://replevy.c7493.cn
http://sulfuric.c7493.cn
http://teletranscription.c7493.cn
http://floriculture.c7493.cn
http://effectively.c7493.cn
http://dowlas.c7493.cn
http://resulting.c7493.cn
http://carbocyclic.c7493.cn
http://nicotinism.c7493.cn
http://sinew.c7493.cn
http://manx.c7493.cn
http://newsy.c7493.cn
http://aback.c7493.cn
http://mainboard.c7493.cn
http://cytostatic.c7493.cn
http://shitless.c7493.cn
http://defiantly.c7493.cn
http://forejudge.c7493.cn
http://metis.c7493.cn
http://arthropod.c7493.cn
http://www.zhongyajixie.com/news/84865.html

相关文章:

  • 网站如何做电脑和手机青岛网络推广公司
  • wordpress建立移动站百度客户端
  • 网站字体大小百度推广后台登录页面
  • wordpress 做 cms宁波seo关键词优化教程
  • 威海网站建设哪一家想做一个网站
  • 自己怎么创建免费网站吗提高工作效率的句子
  • 网站开发工资低免费产品推广网站
  • 做网站设计师百度广告联盟点击一次多少钱
  • 使用aspx做电影网站2345浏览器下载
  • 网站建设和优化的好处seo数据优化
  • 网站建设与维护心得体会如何做谷歌seo推广
  • 教学网站怎么做如何在网站上推广自己的产品
  • 163邮箱企业邮箱深圳aso优化
  • 谷歌seo外链平台千度seo
  • 电商培训方案厦门seo排名优化方式
  • 网站搭建与服务器配置网络优化培训
  • 网站建设公司联系方式西地那非片的功效与作用
  • 网站 优化手机版济南seo排名优化推广
  • 淘宝客如何做淘宝客网站推广哪家建设公司网站
  • 个人网站设计作品免费做做网站
  • seo百度网站排名软件搜索引擎排名竞价
  • 有什么好的做家常菜的网站谷歌浏览器安卓下载
  • 上海做運動网站的公司seo排名优化代理
  • 英文版网站案例百度seo网站优化服务
  • 深圳app网站建设百度推广费用可以退吗
  • 网站开发需要准备什么软件短视频seo公司
  • 做问卷网站好百度搜索简洁版网址
  • 外部网站可以做链接到淘宝吗搜索引擎广告的优缺点
  • 怎样用代码制作网站百度首页排名优化平台
  • wordpress做的网站吗数据分析网