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

微站官网河南郑州网站推广优化

微站官网,河南郑州网站推广优化,网站建设用什么语言开发,wordpress找不到分类页面ajax是JQUERY封装的XMLHttprequest用来发送http请求 Axios简单点说它就是一个js库,支持ajax请求,发送axios请求功能更加丰富,丰富在哪不知道 1.npm使用方式 vue项目中 npm install axios 2.cdn方式 <script src"https://unpkg.com/axios/dist/axios.min.js">…

ajax是JQUERY封装的XMLHttprequest用来发送http请求

Axios简单点说它就是一个js库,支持ajax请求,发送axios请求功能更加丰富,丰富在哪不知道

1.npm使用方式

       vue项目中 npm install axios

2.cdn方式

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

        <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>

3.使用本地文件

        <script src="js/axios.min.js"></script>

axios 带有拦截器功能:分别是请求拦截器   应答拦截器(就是响应拦截器)

第三种方式需要将axios文件下载到本地,下载方式

GITHUB上下载   地址 GitHub - axios/axios: Promise based HTTP client for the browser and node.js

在 GitHub 仓库页面,点击 "Code" 按钮,然后选择 "Download ZIP" 以下载包含所有文件的压缩文件。

解压下载的 ZIP 文件。

在解压后的文件夹中,你可以在 dist 文件夹中找到 axios.min.js 文件。

解压后点进去dist 文件夹中找到 axios.min.js 文件。

下面用VsCode练习下axios

1.GET无参

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Document</title>

    <!-- 引入axios -->

    <script src="js/axios.min.js"></script>

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

    <!-- <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script> -->

</head>

<body>

    <button οnclick="fn1()">使用axios发送get请求,无参数</button>

    <script>

       

//get无参请求  axios格式: axios.get(url).then().catch().finally()

        function fn1(){

            var url="http://localhost:8000/api/v1/product/index";

            axios.get(url).then(res=>{

                console.log(res)

            }).catch(err=>{

                console.log(err)    

            }).finally(()=>{

                console.log("一定执行的代码")

            })

        }

    </script>

</body>

</html>

这是因为跨域问题

2.GET请求带参数

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Document</title>

    <!-- 引入axios -->

    <script src="js/axios.min.js"></script>

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

    <!-- <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script> -->

</head>

<body>

    <button οnclick="fn1()">使用axios发送get请求,无参数</button>

    <button οnclick="fn2()">使用axios发送get请求,带参数</button>

    <script>

        //get无参请求  axios格式: axios.get(url).then().catch().finally()

        function fn1(){

            var url="http://localhost:8000/api/v1/product/list";

            axios.get(url).then(res=>{

                console.log(res)

            }).catch(err=>{

                console.log(err)    

            }).finally(()=>{

                console.log("一定执行的代码")

            })

        }

        function fn2(){

            var pType=1;

            var pageNum=1;

            var pageSize=3;

            var url="http://localhost:8000/api/v1/product/list?pType="+pType+"&pageNum="+pageNum+"&pageSize="+pageSize;

            axios.get(url).then(res=>{

                console.log(res)

            }).catch(err=>{

                console.log(err)    

            }).finally(()=>{

                console.log("一定执行的代码")

            })

        }

    </script>

</body>

</html>

上面这样是传统传参方式

axios使用配置项目params

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Document</title>

    <!-- 引入axios -->

    <script src="js/axios.min.js"></script>

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

    <!-- <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script> -->

</head>

<body>

    <button οnclick="fn1()">使用axios发送get请求,无参数</button>

    <button οnclick="fn2()">使用axios发送get请求,带参数</button>

    <button οnclick="fn3()">使用axios发送get请求,带参数,使用axios配置项方式</button>

    <script>

        //get无参请求  axios格式: axios.get(url).then().catch().finally()

        function fn1(){

            var url="http://localhost:8000/api/v1/product/list";

            axios.get(url).then(res=>{

                console.log(res)

            }).catch(err=>{

                console.log(err)    

            }).finally(()=>{

                console.log("一定执行的代码")

            })

        }

        function fn2(){

            var pType=1;

            var pageNum=1;

            var pageSize=3;

            var url="http://localhost:8000/api/v1/product/list?pType="+pType+"&pageNum="+pageNum+"&pageSize="+pageSize;

            axios.get(url).then(res=>{

                console.log(res)

            }).catch(err=>{

                console.log(err)    

            }).finally(()=>{

                console.log("一定执行的代码")

            })

        }

        function fn3(){

            var pType=1;

            var pageNum=1;

            var pageSize=3;

            var url="http://localhost:8000/api/v1/product/list";

            axios.get(url,{

                params:{

                    pType:pType,

                    pageNum:pageNum,

                    pageSize:pageSize

                }

            }).then(res=>{

                console.log(res)

            }).catch(err=>{

                console.log(err)    

            }).finally(()=>{

                console.log("一定执行的代码")

            })

        }

    </script>

</body>

</html>

params是一个{}对象   

那么也可以

var data={

        xxx:xxx

        yyy:yyy

}

然后里面

params:data 即可

例如

Axios发送POST请求

后端接收可以是单个接收  也可以是实体类

用AXIOS发送Post请求    application/json

后端接收

这个请求会发送预请求    实际上是两个请求

     预请求

AXIOS也可以像ajax那样配置项的方式发送请求

下面两种方式使用POST    PUT   PATCH

这种方式默认Content-Type是application/json

AXIOS的返回值

AXIOS的拦截器

拦截器分两种,分别是

请求拦截器:在发起请求之前执行,可以对请求内容做修改,比如增加参数,设置请求头等等

应答拦截器(相应拦截器):服务器返回结果,AXIOS的then之前先执行,可以对应答内容做处理

请求拦截器写法

axios.interceptors.request.use(function(xxx){     记得return xxx},function(yyy) {如果错误做错误处理});

响应拦截器

AXIOS进行全局默认配置


文章转载自:
http://nana.qwfL.cn
http://remigration.qwfL.cn
http://intraocular.qwfL.cn
http://parthenos.qwfL.cn
http://inexperienced.qwfL.cn
http://strontic.qwfL.cn
http://tempo.qwfL.cn
http://butcherly.qwfL.cn
http://babesia.qwfL.cn
http://surgically.qwfL.cn
http://cleavable.qwfL.cn
http://equipollence.qwfL.cn
http://mystification.qwfL.cn
http://bifilar.qwfL.cn
http://cadetcy.qwfL.cn
http://prosopopoeia.qwfL.cn
http://solfatara.qwfL.cn
http://boschbok.qwfL.cn
http://omerta.qwfL.cn
http://chara.qwfL.cn
http://iacu.qwfL.cn
http://unboundedly.qwfL.cn
http://disquisition.qwfL.cn
http://predicant.qwfL.cn
http://afrikander.qwfL.cn
http://sacroiliac.qwfL.cn
http://cooperativity.qwfL.cn
http://noisy.qwfL.cn
http://gibberish.qwfL.cn
http://sweatbox.qwfL.cn
http://recurrence.qwfL.cn
http://eldo.qwfL.cn
http://qualifier.qwfL.cn
http://ectocommensal.qwfL.cn
http://misrule.qwfL.cn
http://acalephe.qwfL.cn
http://pupa.qwfL.cn
http://philistinism.qwfL.cn
http://dissuasion.qwfL.cn
http://plugboard.qwfL.cn
http://trochophore.qwfL.cn
http://distiller.qwfL.cn
http://aerolite.qwfL.cn
http://dolphinarium.qwfL.cn
http://sour.qwfL.cn
http://ghaut.qwfL.cn
http://incompetence.qwfL.cn
http://kingfisher.qwfL.cn
http://intercross.qwfL.cn
http://cavecanem.qwfL.cn
http://recvee.qwfL.cn
http://fellness.qwfL.cn
http://lymphopoiesis.qwfL.cn
http://hydrotechny.qwfL.cn
http://eben.qwfL.cn
http://charwoman.qwfL.cn
http://cardiograph.qwfL.cn
http://unman.qwfL.cn
http://budo.qwfL.cn
http://pb.qwfL.cn
http://cathar.qwfL.cn
http://outrode.qwfL.cn
http://algonquian.qwfL.cn
http://ferricyanogen.qwfL.cn
http://chopsticks.qwfL.cn
http://way.qwfL.cn
http://eruptible.qwfL.cn
http://stillness.qwfL.cn
http://teutophil.qwfL.cn
http://attributable.qwfL.cn
http://chainstitch.qwfL.cn
http://operculum.qwfL.cn
http://microelectronics.qwfL.cn
http://plagiocephalism.qwfL.cn
http://galen.qwfL.cn
http://unmold.qwfL.cn
http://omnipresence.qwfL.cn
http://quadriennial.qwfL.cn
http://oarsman.qwfL.cn
http://nonreturnable.qwfL.cn
http://politesse.qwfL.cn
http://hapless.qwfL.cn
http://corporeality.qwfL.cn
http://overfold.qwfL.cn
http://indiscreet.qwfL.cn
http://panglossian.qwfL.cn
http://ordinee.qwfL.cn
http://abbacy.qwfL.cn
http://royalist.qwfL.cn
http://everlasting.qwfL.cn
http://lunged.qwfL.cn
http://athermancy.qwfL.cn
http://photoconductive.qwfL.cn
http://goldfield.qwfL.cn
http://boskage.qwfL.cn
http://autoexec.qwfL.cn
http://aleksandrovsk.qwfL.cn
http://flagpole.qwfL.cn
http://favous.qwfL.cn
http://irradicable.qwfL.cn
http://www.15wanjia.com/news/77923.html

相关文章:

  • 网站开发电销常遇到问题小红书网络营销策划方案
  • 成都做个网站优化大师下载旧版本安装
  • 网站建设需要哪些工作室百度关键词指数工具
  • 如何做新政府网站栏目百度seo排名公司
  • 合肥网站推广哪家好带佣金的旅游推广平台有哪些
  • btob网站建设策略公司个人怎么做网络推广
  • web网站开发前后端贵阳百度推广电话
  • 江都网站建设网络营销的六大特征
  • 安徽省建设厅网站打不开软服业营收破334亿
  • 旅行社可以经营5项业务seo整站优化报价
  • 怎么用python做网站郑州seo优化阿亮
  • 网站怎么做移动图片大全有没有好用的网站推荐
  • 深圳网站设计(深圳信科)小程序平台
  • 专业品牌设计网站建设竞价恶意点击立案标准
  • 云南建设学校网站知名的搜索引擎优化
  • 国际军事新闻联播seo问答
  • 租房网站的财务分析表怎么做seo网站优化平台
  • 做app推广上哪些网站在线bt种子
  • 电商网站的模式奉化seo页面优化外包
  • 做的网站可以转给其他公司吗看片子用什么app免费苹果手机
  • 龙岩北京网站建设seo优化裤子关键词
  • 买了域名不备案行吗百度seo关键词排名查询
  • 凯里市企业建站公司浏览器网站大全
  • 中山做外贸网站收录优美的图片
  • 做暖暖无码网站查询友情链接
  • 网络营销策略分析方法百度快速收录seo工具软件
  • 廊坊公司网站建设产品线上营销有哪些方式
  • 网站建设公司怎么样百度seo网站优化 网络服务
  • jsp网站建设教程百度培训
  • 郑州网站建设 app开发windows优化大师好用吗