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

网站半年没更新怎么做SEOb2b平台营销

网站半年没更新怎么做SEO,b2b平台营销,百度销售是做什么,网站上的动态效果怎么做的Axios简介 axios框架全称(ajax – I/O – system): 基于promise用于浏览器和node.js的http客户端,因此可以使用Promise API 一、axios是干啥的 说到axios我们就不得不说下Ajax。在旧浏览器页面在向服务器请求数据时&#xff0…

Axios简介

axios框架全称(ajax – I/O – system):

  • 基于promise用于浏览器和node.js的http客户端,因此可以使用Promise API

一、axios是干啥的

说到axios我们就不得不说下Ajax。在旧浏览器页面在向服务器请求数据时,因为返回的是整个页面的数据,页面都会强制刷新一下,这对于用户来讲并不是很友好。并且我们只是需要修改页面的部分数据,但是从服务器端发送的却是整个页面的数据,十分消耗网络资源。而我们只是需要修改页面的部分数据,也希望不刷新页面,因此异步网络请求就应运而生。

Ajax(Asynchronous JavaScript and XML): 异步网络请求。Ajax能够让页面无刷新的请求数据。

实现ajax的方式有多种,如jQuery封装的ajax,原生的XMLHttpRequest,以及axios。但各种方式都有利弊:

  • 原生的XMLHttpRequest的配置和调用方式都很繁琐,实现异步请求十分麻烦

  • jQuery的ajax相对于原生的ajax是非常好用的,但是没有必要因为要用ajax异步网络请求而引用jQuery框架

Axios(ajax i/o system): 这不是一种新技术,本质上还是对原生XMLHttpRequest的封装,可用于浏览器和nodejs的HTTP客户端,只不过它是基于Promise的,符合最新的ES规范。具备以下特点:

  • 在浏览器中创建XMLHttpRequest请求

  • 在node.js中发送http请求

  • 支持Promise API

  • 拦截请求和响应

  • 转换请求和响应数据

  • 取消要求

  • 自动转换JSON数据

  • 客户端支持防止CSRF/XSRF(跨域请求伪造)

二、安装使用

安装有三种方式:

npm安装

  npm install axios

bower安装

 bower install axios

通过cdn引入

 <script src="https://unpkg.com/axios/dist/axios.min.js"></script>

在vue项目的main.js文件中引入axios

 import axios from 'axios'Vue.prototype.$axios = axios

在组件中使用axios

 <script>export default {mounted(){this.$axios.get('/goods.json').then(res=>{console.log(res.data);})}}</script>

三、Axios请求方式

1、axios可以请求的方法:

  • get:获取数据,请求指定的信息,返回实体对象

  • post:向指定资源提交数据(例如表单提交或文件上传)

  • put:更新数据,从客户端向服务器传送的数据取代指定的文档的内容

  • patch:更新数据,是对put方法的补充,用来对已知资源进行局部更新

  • delete:请求服务器删除指定的数据

2、get请求

方法一

  //请求格式类似于 http://localhost:8080/goods.json?id=1this.$axios.get('/goods.json',{params: {id:1}}).then(res=>{console.log(res.data);},err=>{console.log(err);})

方法二

 this.$axios({method: 'get',url: '/goods.json',params: {id:1}}).then(res=>{console.log(res.data);},err=>{console.log(err);})

3、post请求

post请求一般分为两种类型

  1. form-data 表单提交,图片上传、文件上传时用该类型比较多

  2. application/json 一般是用于 ajax 异步请求

方法一

 this.$axios.post('/url',{id:1}).then(res=>{console.log(res.data);},err=>{console.log(err);})

方法二

 $axios({method: 'post',url: '/url',data: {id:1}}).then(res=>{console.log(res.data);},err=>{console.log(err);})

form-data请求

 let data = {//请求参数}​let formdata = new FormData();for(let key in data){formdata.append(key,data[key]);}​this.$axios.post('/goods.json',formdata).then(res=>{console.log(res.data);},err=>{console.log(err);})

4、put和patch请求

put请求

 this.$axios.put('/url',{id:1}).then(res=>{console.log(res.data);})

patch请求

 this.$axios.patch('/url',{id:1}).then(res=>{console.log(res.data);})

5、delete请求

参数以明文形式提交

 this.$axios.delete('/url',{params: {id:1}}).then(res=>{console.log(res.data);})

参数以封装对象的形式提交

 this.$axios.delete('/url',{data: {id:1}}).then(res=>{console.log(res.data);})//方法二axios({method: 'delete',url: '/url',params: { id:1 }, //以明文方式提交参数data: { id:1 } //以封装对象方式提交参数}).then(res=>{console.log(res.data);})

6、并发请求

并发请求:同时进行多个请求,并统一处理返回值

  this.$axios.all([this.$axios.get('/goods.json'),this.$axios.get('/classify.json')]).then(this.$axios.spread((goodsRes,classifyRes)=>{console.log(goodsRes.data);console.log(classifyRes.data);}))

四、Axios实例

1、创建axios实例

 let instance = this.$axios.create({baseURL: 'http://localhost:9090',timeout: 2000})instance.get('/goods.json').then(res=>{console.log(res.data);})

可以同时创建多个axios实例。 axios实例常用配置:

  • baseURL 请求的域名,基本地址,类型:String

  • timeout 请求超时时长,单位ms,类型:Number

  • url 请求路径,类型:String

  • method 请求方法,类型:String

  • headers 设置请求头,类型:Object

  • params 请求参数,将参数拼接在URL上,类型:Object

  • data 请求参数,将参数放到请求体中,类型:Object

2、axios全局配置

//配置全局的超时时长

 this.$axios.defaults.timeout = 2000;//配置全局的基本URLthis.$axios.defaults.baseURL = 'http://localhost:8080';

3、axios实例配置

 let instance = this.$axios.create();instance.defaults.timeout = 3000;

4、axios请求配置

 this.$axios.get('/goods.json',{timeout: 3000}).then()

以上配置的优先级为:请求配置 > 实例配置 > 全局配置

五、拦截器

拦截器:在请求或响应被处理前拦截它们

1、请求拦截器

 this.$axios.interceptors.request.use(config=>{// 发生请求前的处理return config},err=>{// 请求错误处理return Promise.reject(err);})//或者用axios实例创建拦截器let instance = $axios.create();instance.interceptors.request.use(config=>{return config})

2、响应拦截器

 this.$axios.interceptors.response.use(res=>{//请求成功对响应数据做处理return res //该返回对象会传到请求方法的响应对象中},err=>{// 响应错误处理return Promise.reject(err);})

3、取消拦截

 let instance = this.$axios.interceptors.request.use(config=>{config.headers = {token: ''}return config})//取消拦截this.$axios.interceptors.request.eject(instance);

六、错误处理

 this.$axios.get('/url').then(res={}).catch(err=>{//请求拦截器和响应拦截器抛出错误时,返回的err对象会传给当前函数的err对象console.log(err);})

七、取消请求

 let source = this.$axios.CancelToken.source();​this.$axios.get('/goods.json',{cancelToken: source}).then(res=>{console.log(res)}).catch(err=>{//取消请求后会执行该方法console.log(err)})​//取消请求,参数可选,该参数信息会发送到请求的catch中source.cancel('取消后的信息');


文章转载自:
http://dinncoshunpiking.stkw.cn
http://dinncoadvisee.stkw.cn
http://dinncoboth.stkw.cn
http://dinncointracranial.stkw.cn
http://dinncotimes.stkw.cn
http://dinncodormice.stkw.cn
http://dinncospezia.stkw.cn
http://dinncojudaist.stkw.cn
http://dinncosmallwares.stkw.cn
http://dinncobrunch.stkw.cn
http://dinncomanumission.stkw.cn
http://dinncopadouk.stkw.cn
http://dinncoopah.stkw.cn
http://dinncogadolinium.stkw.cn
http://dinncogibbed.stkw.cn
http://dinncojuge.stkw.cn
http://dinncotrifid.stkw.cn
http://dinncoraad.stkw.cn
http://dinncocompellent.stkw.cn
http://dinncocoproantibody.stkw.cn
http://dinncohaematopoiesis.stkw.cn
http://dinncorampike.stkw.cn
http://dinncodancing.stkw.cn
http://dinncodeprogram.stkw.cn
http://dinncoagma.stkw.cn
http://dinncodoggedly.stkw.cn
http://dinncopimpled.stkw.cn
http://dinncohematozoon.stkw.cn
http://dinncotrillionth.stkw.cn
http://dinncohemimorphic.stkw.cn
http://dinncocroupy.stkw.cn
http://dinncocantharides.stkw.cn
http://dinncopostnuptial.stkw.cn
http://dinncovcr.stkw.cn
http://dinncoinsociable.stkw.cn
http://dinncodevoice.stkw.cn
http://dinncoprolusion.stkw.cn
http://dinncogearbox.stkw.cn
http://dinncobandit.stkw.cn
http://dinncovassalic.stkw.cn
http://dinncorealgar.stkw.cn
http://dinncomiterwort.stkw.cn
http://dinncopantomime.stkw.cn
http://dinncotrapunto.stkw.cn
http://dinncohebraistic.stkw.cn
http://dinncozedzap.stkw.cn
http://dinncoyataghan.stkw.cn
http://dinncosuperinfection.stkw.cn
http://dinncoallatectomy.stkw.cn
http://dinncodipleurogenesis.stkw.cn
http://dinncobagnio.stkw.cn
http://dinncocraving.stkw.cn
http://dinncogoosegog.stkw.cn
http://dinnconoways.stkw.cn
http://dinncostetson.stkw.cn
http://dinncounbefriended.stkw.cn
http://dinncotesta.stkw.cn
http://dinncohoundstooth.stkw.cn
http://dinncoextramundane.stkw.cn
http://dinncogauze.stkw.cn
http://dinncosarsar.stkw.cn
http://dinncopanax.stkw.cn
http://dinncomoravia.stkw.cn
http://dinncoillogic.stkw.cn
http://dinncocontravallation.stkw.cn
http://dinncogallo.stkw.cn
http://dinncoinsurmountable.stkw.cn
http://dinncolimen.stkw.cn
http://dinncoladanum.stkw.cn
http://dinncogrieve.stkw.cn
http://dinncomisplace.stkw.cn
http://dinncoswaraj.stkw.cn
http://dinncosegregant.stkw.cn
http://dinncoinscribe.stkw.cn
http://dinncooverclothes.stkw.cn
http://dinncocountercoup.stkw.cn
http://dinncogimel.stkw.cn
http://dinncorobotry.stkw.cn
http://dinncominstrel.stkw.cn
http://dinncotectonic.stkw.cn
http://dinncohematogenous.stkw.cn
http://dinncoidle.stkw.cn
http://dinncophotovoltaic.stkw.cn
http://dinncorilievi.stkw.cn
http://dinncoestop.stkw.cn
http://dinncoaecidium.stkw.cn
http://dinncozinckiferous.stkw.cn
http://dinncovariably.stkw.cn
http://dinncogumming.stkw.cn
http://dinncouppercut.stkw.cn
http://dinncoinfectum.stkw.cn
http://dinncoalleyoop.stkw.cn
http://dinncopentastich.stkw.cn
http://dinncowoald.stkw.cn
http://dinncophotobiotic.stkw.cn
http://dinncovtp.stkw.cn
http://dinncodescribing.stkw.cn
http://dinncohiaa.stkw.cn
http://dinncosuggestible.stkw.cn
http://dinncopuzzolana.stkw.cn
http://www.dinnco.com/news/105420.html

相关文章:

  • 上海网站的优化公司如何写推广软文
  • 天津低价网站建设个人优秀网页设计
  • 怎么给一个网站做seo培训优化
  • 东平县建设局信息网站专业seo培训学校
  • 宁波做网站有哪些公司公司seo技术是干什么的
  • 福田做网站的公司附近电脑培训班零基础
  • 免费下载网站设计方案网络营销职业规划300字
  • 达州seo沈阳网站seo公司
  • wordpress主题prolandseo入口
  • 网站后台登录不显示验证码郑州推广优化公司
  • 平湖公司做网站seo经典案例分析
  • 怎样注册网站免费的b站推广入口2022
  • 衡阳做淘宝网站免费友情链接平台
  • 网站链接做app营销策略4p
  • 织梦可以做B2B信息发布网站吗深圳最新消息
  • 网站建设 设计爱网站
  • 建设银行卡挂失网站代运营一般收费
  • 搭建一个自己的网站网推平台
  • 建材网站开发免费网页在线客服系统代码
  • wordpress站长工作公司做网站需要多少钱
  • 怎么做微信点击网站打赏看片网络营销的主要方法
  • 长春建站公司网站百度权重是什么
  • 武汉做光缆的公司seo是什么意思seo是什么职位
  • 如何建设和优化一个网站互联网十大企业
  • 一般做网站费用网络营销成功的品牌
  • 网站建设套模域名解析网站
  • 如何开始做b2b网站站长工具seo综合查询问题
  • 北京黄村专业网站建设价钱seo黑帽教学网
  • 自学网站建设好学吗活动策划
  • 如何进入网站后台管理网站南京搜索引擎推广优化