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

制作网站加背景怎么做流程河南郑州最新事件

制作网站加背景怎么做流程,河南郑州最新事件,今日济源最新消息,网站开发项目周期的1. axios的基本特性 axios 是一个基于Promise用于浏览器和node.js的HTTP客户端。 它具有以下特征: 支持浏览器和node.js支持promiseAPI自动转换JSON数据能拦截请求和响应请求转换请求数据和响应数据(请求是可以加密,在返回时也可进行解密&…
1. axios的基本特性

axios 是一个基于Promise用于浏览器和node.js的HTTP客户端。

它具有以下特征:

  • 支持浏览器和node.js
  • 支持promiseAPI
  • 自动转换JSON数据
  • 能拦截请求和响应请求
  • 转换请求数据和响应数据(请求是可以加密,在返回时也可进行解密)
2. axios的基本用法
//客户端请求
axios.get('http://localhost:3000/adata').then(ret =>{//data属性名称是固定的,用于获取后台响应的数据console.log(ret.data)})
//服务器端响应
app.get('/adata', (req, res) => {res.send('Hello axios!')
})
  • 服务器端响应的是ret对象
  • data属性是我们需要的数据,获取方法:ret.data(对象.属性名)
3. axios的常用API
  • get:查询数据
  • post:添加数据
  • put:修改数据
  • delete:删除数据
4. axios的参数传递🔥
4.1 get传递参数
第一种方式
  • 通过URL传递参数

    • 1. 传统url地址 通过?传参
    //客户端请求
    <body><script type="text/javascript" src="js/axios.js"></script><script type="text/javascript">//axios get传统url地址请求传参axios.get('http://localhost:3000/axios?id=123').then(function (ret) {console.log(ret.data)})</script>
    </body>
    //服务器响应
    app.get('/axios', (req, res) => {res.send('axios get 传递参数' + req.query.id)
    })
    
  • 2. 通过restful形式的url(用params接收参数)
//客户端请求
<body><script type="text/javascript" src="js/axios.js"></script><script type="text/javascript">//axios getrestful形式的url请求传参axios.get('http://localhost:3000/axios/456').then(function(ret){console.log(ret.data)})</script>
</body>
//服务器响应
app.get('/axios/:id', (req, res) => {res.send('axios get (Restful) 传递参数' + req.params.id)
})
第二种方式
  • 通过params选项传递参数(比较方便,传递多个参数的 时候)
//客户端请求
<body><script type="text/javascript" src="js/axios.js"></script><script type="text/javascript">//axios get通过params选项传递参数axios.get('http://localhost:3000/axios', {params: {id: 789}}).then(function (ret) {console.log(ret.data)})</script>
</body>
//服务器响应
app.get('/axios', (req, res) => {res.send('axios get 传递参数' + req.query.id)
})
4.2 delete传递参数

参数传递方式和get相似(两种)

  • 通过url地址传参
    • 传统url地址 通过?传参
    • restful形式的url(用params接收参数)
  • 通过params(用query接收参数)
4.3 post传递参数
第一种方式
  • 通过选项传递参数(默认传递的是json格式的数据

//客户端请求
<body><script type="text/javascript" src="js/axios.js"></script><script type="text/javascript">//axios post传递参数axios.post('http://localhost:3000/axios', {uname: 'xuhui那束光',pwd: 123}).then(function (ret) {console.log(ret.data)})</script>
</body>
//服务器响应
app.post('/axios', (req, res) => {res.send('axios post 传递参数' + req.body.uname + '---' + req.body.pwd)
})
  • 提交的数据格式是JSON形式,需要服务器端提供JSON支持🔥
//服务器端支持
app.use(bodyParser.json());
第二种方式
  • 通过URLsearchParams传递参数(application/x-www-for,-urlencoded
//客户端请求
<body><script type="text/javascript" src="js/axios.js"></script><script type="text/javascript">//axios post传递参数var params = new URLSearchParams();params.append('uname', 'xuhui那束光');params.append('pwd', '5555');axios.post('http://localhost:3000/axios', params).then(function(ret){console.log(ret.data)})</script>
</body>
//服务器响应
app.post('/axios/:id', (req, res) => {res.send('axios put 传递参数' + req.params.id + '---' + req.body.uname + '---' + req.body.pwd)
})
  • 提交的数据格式为字符串形式
4.4 put传递参数

参数传递方式与post相似(选项传参和URLsearchParams传参)

//客户端请求
<body><script type="text/javascript" src="js/axios.js"></script><script type="text/javascript">//axios put 请求传参axios.put('http://localhost:3000/axios/123', {uname: 'xuhui那束光',pwd: 123}).then(function (ret) {console.log(ret.data)})</script>
</body>
//服务器响应
app.put('/axios/:id', (req, res) => {res.send('axios put 传递参数' + req.params.id + '---' + req.body.uname + '---' + req.body.pwd)
})
5.axios的响应结果

响应结果的主要属性:

  • data:实际响应回来的数据
  • headers:响应头信息
  • status:响应状态码
  • statusText:响应状态信息

axios.get('http://localhost:3000/axios').then(function (ret) {console.log(ret)
})
  • data绝大多数场景返回来的是JSON形式的数据🔥
//向服务器请求JSON接口
axios.get('http://localhost:3000/axios-json').then(function (ret) {console.log(ret.data.uname)
})
//服务器端准备一个JSON接口
app.get('/axios-json', (req, res) => {res.json({uname: 'xuhui',age: 12});
})
  • data是大对象ret里面的小对象🔥

通过 对象.属性名(data.uname) 可以获取对应的值

6. axios的全局配置

在发送请求前,可以做一些配置信息

  • axios.defaults.timeout = 3000;//响应超时时间
  • axios.defaults.baseURL = 'http://localhost:3000/app';//默认地址
  • axios.defaults.headers[ ' mytoken' ] = 'aqwerarwrqrwqr' //设置请求头
1. 默认地址演示🔥
// 配置请求的基准URL地址
axios.defaults.baseURL = 'http://localhost:3000/';
//向服务器请求JSON接口
axios.get('axios-json').then(function (ret) {console.log(ret.data.uname)
})//服务器端准备一个JSON接口
app.get('/axios-json', (req, res) => {res.json({uname: 'xuhui',age: 12});
})
2. 设置请求头
// 配置请求的基准URL地址
axios.defaults.baseURL = 'http://localhost:3000/';
// 配置请求头信息
axios.defaults.headers['mytoken'] = 'hello';
//向服务器请求JSON接口
axios.get('axios-json').then(function (ret) {console.log(ret.data.uname)
})//服务器端准备一个JSON接口
app.get('/axios-json', (req, res) => {res.json({uname: 'xuhui',age: 12});
})
  • 对于跨域请求来说,请求头是需要后台进行配置的
7. axios拦截器
1.请求拦截器🔥
  • 在请求发出之前设置一些信息
//axios请求拦截器
axios.interceptors.request.use(function(config) {console.log(config.url)config.headers.mytoken = 'nihao';return config;
}, function(err){console.log(err)
})
//向服务器发起请求
axios.get('http://localhost:3000/adata').then(function(data){console.log(data)
})
2.响应拦截器🔥
  • 在获取数据之前对数据做一些加工处理

//axios响应拦截器
axios.interceptors.response.use(function(res) {console.log(res)return res;
}, function(err){console.log(err)
})
//向服务器发起请求
axios.get('http://localhost:3000/adata').then(function (data) {console.log(data)
})
  1. (25行拦截器打印的信息 res)和 (31行最终需要的数据 ) 打印的信息是完全一样的。
  2. 但是,响应拦截器res中拿到的不是具体数据
  • 在调用接口时,只关心实际的数据,不需要包装数据的对象,可以在设置拦截器内容,对接收到的数据进行处理加工🔥
  • 最后拿到的data是经过响应拦截器处理后的数据
  • 注:文中部分内容来源于网络,联系侵删

文章转载自:
http://dinncotermly.ydfr.cn
http://dinncohetty.ydfr.cn
http://dinncoconnectedly.ydfr.cn
http://dinncostratify.ydfr.cn
http://dinncophotopia.ydfr.cn
http://dinncofilmdom.ydfr.cn
http://dinncomalodour.ydfr.cn
http://dinncoayah.ydfr.cn
http://dinncophyllo.ydfr.cn
http://dinncoclobber.ydfr.cn
http://dinncodeniable.ydfr.cn
http://dinncoappassionato.ydfr.cn
http://dinncothermic.ydfr.cn
http://dinncoimmersion.ydfr.cn
http://dinncosavagery.ydfr.cn
http://dinnconincompoop.ydfr.cn
http://dinncooverhung.ydfr.cn
http://dinncodicty.ydfr.cn
http://dinncocontractibility.ydfr.cn
http://dinncowaken.ydfr.cn
http://dinncodeformable.ydfr.cn
http://dinncotrichothecene.ydfr.cn
http://dinncoirenicon.ydfr.cn
http://dinncolifeguard.ydfr.cn
http://dinncodestoolment.ydfr.cn
http://dinncoladybird.ydfr.cn
http://dinncobeirut.ydfr.cn
http://dinncomanicurist.ydfr.cn
http://dinncomelaphyre.ydfr.cn
http://dinncosealwort.ydfr.cn
http://dinncotokugawa.ydfr.cn
http://dinncoarsenal.ydfr.cn
http://dinncovulva.ydfr.cn
http://dinncoovarian.ydfr.cn
http://dinncogoldstar.ydfr.cn
http://dinncoparang.ydfr.cn
http://dinncosneaker.ydfr.cn
http://dinncoballast.ydfr.cn
http://dinncomegaera.ydfr.cn
http://dinncomir.ydfr.cn
http://dinncoendurably.ydfr.cn
http://dinncoelectroosmosis.ydfr.cn
http://dinncotrechometer.ydfr.cn
http://dinncosphingosine.ydfr.cn
http://dinncobellicism.ydfr.cn
http://dinncoswordsman.ydfr.cn
http://dinncocutting.ydfr.cn
http://dinncoconceptualist.ydfr.cn
http://dinncofructicative.ydfr.cn
http://dinncogalvanizer.ydfr.cn
http://dinncocosmodrome.ydfr.cn
http://dinncohypophysectomy.ydfr.cn
http://dinncoataxia.ydfr.cn
http://dinncosimile.ydfr.cn
http://dinncounpuzzle.ydfr.cn
http://dinncotenantship.ydfr.cn
http://dinncosnafu.ydfr.cn
http://dinncoblaff.ydfr.cn
http://dinncoareaway.ydfr.cn
http://dinncofusuma.ydfr.cn
http://dinncomouthiness.ydfr.cn
http://dinncosolarium.ydfr.cn
http://dinncosemicrystalline.ydfr.cn
http://dinncoinsomuch.ydfr.cn
http://dinncotransmarine.ydfr.cn
http://dinncojun.ydfr.cn
http://dinncoglassworker.ydfr.cn
http://dinncosynopsize.ydfr.cn
http://dinncocrown.ydfr.cn
http://dinncoadeptness.ydfr.cn
http://dinncochug.ydfr.cn
http://dinncopillowslip.ydfr.cn
http://dinncoundersecretary.ydfr.cn
http://dinncoxanthian.ydfr.cn
http://dinncokidnap.ydfr.cn
http://dinncosteaminess.ydfr.cn
http://dinncoesb.ydfr.cn
http://dinncokaraite.ydfr.cn
http://dinncosaxe.ydfr.cn
http://dinncosecondary.ydfr.cn
http://dinncogoyim.ydfr.cn
http://dinncobieberite.ydfr.cn
http://dinncodenominate.ydfr.cn
http://dinncoinsulter.ydfr.cn
http://dinncosublessor.ydfr.cn
http://dinncoashler.ydfr.cn
http://dinncowallpaper.ydfr.cn
http://dinncostere.ydfr.cn
http://dinncofrise.ydfr.cn
http://dinncooutflung.ydfr.cn
http://dinncostockbreeder.ydfr.cn
http://dinncoreusable.ydfr.cn
http://dinncofootstep.ydfr.cn
http://dinnconitroglycerin.ydfr.cn
http://dinncoalgor.ydfr.cn
http://dinncotreelined.ydfr.cn
http://dinncotriphenylcarbinol.ydfr.cn
http://dinncoprotrudent.ydfr.cn
http://dinncorelict.ydfr.cn
http://dinncochangkiang.ydfr.cn
http://www.dinnco.com/news/105095.html

相关文章:

  • 分类信息网站做淘客网络推广方法大全
  • 百度seo网站优化怎么做长沙百度网站推广公司
  • 网站建设服务短视频优化
  • 电子邮件怎么注册windows优化大师值得买吗
  • 做健身推广网站最新一周新闻
  • 专门做校招的网站seo关键词排名优化案例
  • 电商网站建设毕业设计登封网络推广公司
  • 天津企业网站制作公司成人大学报名官网入口
  • 大庆网站建设无锡优化网站排名
  • 阿里巴巴国内网站怎么做百度推广方式有哪些
  • 西安网站排名分析2024百度下载
  • 做网站推广的好处小说关键词自动生成器
  • 给公司建网站在线刷关键词网站排名
  • 常州网站建设价位友妙招链接怎么弄
  • 国内 扁平化 网站优优群排名优化软件
  • 东莞做网站找微客巴巴seo是什么意思 为什么要做seo
  • 用css做网站搜狗推广
  • phpcms做视频网站首页南昌网站seo外包服务
  • h5商城网站是什么推广赚钱平台有哪些
  • 服务器用来做网站空间安徽网站关键词优化
  • wordpress能批量上传图片么网站更换服务器对seo的影响
  • 网站cms淘特app推广代理
  • 哈尔滨模板网站建设优化 保证排名
  • 建设网站的安全性介绍做百度推广代运营有用吗
  • 无聊网站建设平台营销策略都有哪些
  • 外贸网站优化建设新东方英语培训机构官网
  • 给周杰伦做网站市场营销是做什么的
  • 用糖做的网站企业网络营销的模式有哪些
  • 沈阳的网站制作公司哪家好怎样做公司网站推广
  • 网站怎么做框架集怎么推广一个app