中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁(yè) > news >正文

電影里的做視頻在線觀看網(wǎng)站無(wú)貨源網(wǎng)店怎么開(kāi)

電影里的做視頻在線觀看網(wǎng)站,無(wú)貨源網(wǎng)店怎么開(kāi),國(guó)際網(wǎng)絡(luò)交易平臺(tái),上海市建筑信息平臺(tái)1. axios的基本特性 axios 是一個(gè)基于Promise用于瀏覽器和node.js的HTTP客戶端。 它具有以下特征: 支持瀏覽器和node.js支持promiseAPI自動(dòng)轉(zhuǎn)換JSON數(shù)據(jù)能攔截請(qǐng)求和響應(yīng)請(qǐng)求轉(zhuǎn)換請(qǐng)求數(shù)據(jù)和響應(yīng)數(shù)據(jù)(請(qǐng)求是可以加密,在返回時(shí)也可進(jìn)行解密&…
1. axios的基本特性

axios 是一個(gè)基于Promise用于瀏覽器和node.js的HTTP客戶端。

它具有以下特征:

  • 支持瀏覽器和node.js
  • 支持promiseAPI
  • 自動(dòng)轉(zhuǎn)換JSON數(shù)據(jù)
  • 能攔截請(qǐng)求和響應(yīng)請(qǐng)求
  • 轉(zhuǎn)換請(qǐng)求數(shù)據(jù)和響應(yīng)數(shù)據(jù)(請(qǐng)求是可以加密,在返回時(shí)也可進(jìn)行解密)
2. axios的基本用法
//客戶端請(qǐng)求
axios.get('http://localhost:3000/adata').then(ret =>{//data屬性名稱是固定的,用于獲取后臺(tái)響應(yīng)的數(shù)據(jù)console.log(ret.data)})
//服務(wù)器端響應(yīng)
app.get('/adata', (req, res) => {res.send('Hello axios!')
})
  • 服務(wù)器端響應(yīng)的是ret對(duì)象
  • data屬性是我們需要的數(shù)據(jù),獲取方法:ret.data(對(duì)象.屬性名)
3. axios的常用API
  • get:查詢數(shù)據(jù)
  • post:添加數(shù)據(jù)
  • put:修改數(shù)據(jù)
  • delete:刪除數(shù)據(jù)
4. axios的參數(shù)傳遞🔥
4.1 get傳遞參數(shù)
第一種方式
  • 通過(guò)URL傳遞參數(shù)

    • 1. 傳統(tǒng)url地址 通過(guò)?傳參
    //客戶端請(qǐng)求
    <body><script type="text/javascript" src="js/axios.js"></script><script type="text/javascript">//axios get傳統(tǒng)url地址請(qǐng)求傳參axios.get('http://localhost:3000/axios?id=123').then(function (ret) {console.log(ret.data)})</script>
    </body>
    //服務(wù)器響應(yīng)
    app.get('/axios', (req, res) => {res.send('axios get 傳遞參數(shù)' + req.query.id)
    })
    
  • 2. 通過(guò)restful形式的url(用params接收參數(shù))
//客戶端請(qǐng)求
<body><script type="text/javascript" src="js/axios.js"></script><script type="text/javascript">//axios getrestful形式的url請(qǐng)求傳參axios.get('http://localhost:3000/axios/456').then(function(ret){console.log(ret.data)})</script>
</body>
//服務(wù)器響應(yīng)
app.get('/axios/:id', (req, res) => {res.send('axios get (Restful) 傳遞參數(shù)' + req.params.id)
})
第二種方式
  • 通過(guò)params選項(xiàng)傳遞參數(shù)(比較方便,傳遞多個(gè)參數(shù)的 時(shí)候)
//客戶端請(qǐng)求
<body><script type="text/javascript" src="js/axios.js"></script><script type="text/javascript">//axios get通過(guò)params選項(xiàng)傳遞參數(shù)axios.get('http://localhost:3000/axios', {params: {id: 789}}).then(function (ret) {console.log(ret.data)})</script>
</body>
//服務(wù)器響應(yīng)
app.get('/axios', (req, res) => {res.send('axios get 傳遞參數(shù)' + req.query.id)
})
4.2 delete傳遞參數(shù)

參數(shù)傳遞方式和get相似(兩種)

  • 通過(guò)url地址傳參
    • 傳統(tǒng)url地址 通過(guò)?傳參
    • restful形式的url(用params接收參數(shù))
  • 通過(guò)params(用query接收參數(shù))
4.3 post傳遞參數(shù)
第一種方式
  • 通過(guò)選項(xiàng)傳遞參數(shù)(默認(rèn)傳遞的是json格式的數(shù)據(jù)

//客戶端請(qǐng)求
<body><script type="text/javascript" src="js/axios.js"></script><script type="text/javascript">//axios post傳遞參數(shù)axios.post('http://localhost:3000/axios', {uname: 'xuhui那束光',pwd: 123}).then(function (ret) {console.log(ret.data)})</script>
</body>
//服務(wù)器響應(yīng)
app.post('/axios', (req, res) => {res.send('axios post 傳遞參數(shù)' + req.body.uname + '---' + req.body.pwd)
})
  • 提交的數(shù)據(jù)格式是JSON形式,需要服務(wù)器端提供JSON支持🔥
//服務(wù)器端支持
app.use(bodyParser.json());
第二種方式
  • 通過(guò)URLsearchParams傳遞參數(shù)(application/x-www-for,-urlencoded
//客戶端請(qǐng)求
<body><script type="text/javascript" src="js/axios.js"></script><script type="text/javascript">//axios post傳遞參數(shù)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>
//服務(wù)器響應(yīng)
app.post('/axios/:id', (req, res) => {res.send('axios put 傳遞參數(shù)' + req.params.id + '---' + req.body.uname + '---' + req.body.pwd)
})
  • 提交的數(shù)據(jù)格式為字符串形式
4.4 put傳遞參數(shù)

參數(shù)傳遞方式與post相似(選項(xiàng)傳參和URLsearchParams傳參)

//客戶端請(qǐng)求
<body><script type="text/javascript" src="js/axios.js"></script><script type="text/javascript">//axios put 請(qǐng)求傳參axios.put('http://localhost:3000/axios/123', {uname: 'xuhui那束光',pwd: 123}).then(function (ret) {console.log(ret.data)})</script>
</body>
//服務(wù)器響應(yīng)
app.put('/axios/:id', (req, res) => {res.send('axios put 傳遞參數(shù)' + req.params.id + '---' + req.body.uname + '---' + req.body.pwd)
})
5.axios的響應(yīng)結(jié)果

響應(yīng)結(jié)果的主要屬性:

  • data:實(shí)際響應(yīng)回來(lái)的數(shù)據(jù)
  • headers:響應(yīng)頭信息
  • status:響應(yīng)狀態(tài)碼
  • statusText:響應(yīng)狀態(tài)信息

axios.get('http://localhost:3000/axios').then(function (ret) {console.log(ret)
})
  • data絕大多數(shù)場(chǎng)景返回來(lái)的是JSON形式的數(shù)據(jù)🔥
//向服務(wù)器請(qǐng)求JSON接口
axios.get('http://localhost:3000/axios-json').then(function (ret) {console.log(ret.data.uname)
})
//服務(wù)器端準(zhǔn)備一個(gè)JSON接口
app.get('/axios-json', (req, res) => {res.json({uname: 'xuhui',age: 12});
})
  • data是大對(duì)象ret里面的小對(duì)象🔥

通過(guò) 對(duì)象.屬性名(data.uname) 可以獲取對(duì)應(yīng)的值

6. axios的全局配置

在發(fā)送請(qǐng)求前,可以做一些配置信息

  • axios.defaults.timeout = 3000;//響應(yīng)超時(shí)時(shí)間
  • axios.defaults.baseURL = 'http://localhost:3000/app';//默認(rèn)地址
  • axios.defaults.headers[ ' mytoken' ] = 'aqwerarwrqrwqr' //設(shè)置請(qǐng)求頭
1. 默認(rèn)地址演示🔥
// 配置請(qǐng)求的基準(zhǔn)URL地址
axios.defaults.baseURL = 'http://localhost:3000/';
//向服務(wù)器請(qǐng)求JSON接口
axios.get('axios-json').then(function (ret) {console.log(ret.data.uname)
})//服務(wù)器端準(zhǔn)備一個(gè)JSON接口
app.get('/axios-json', (req, res) => {res.json({uname: 'xuhui',age: 12});
})
2. 設(shè)置請(qǐng)求頭
// 配置請(qǐng)求的基準(zhǔn)URL地址
axios.defaults.baseURL = 'http://localhost:3000/';
// 配置請(qǐng)求頭信息
axios.defaults.headers['mytoken'] = 'hello';
//向服務(wù)器請(qǐng)求JSON接口
axios.get('axios-json').then(function (ret) {console.log(ret.data.uname)
})//服務(wù)器端準(zhǔn)備一個(gè)JSON接口
app.get('/axios-json', (req, res) => {res.json({uname: 'xuhui',age: 12});
})
  • 對(duì)于跨域請(qǐng)求來(lái)說(shuō),請(qǐng)求頭是需要后臺(tái)進(jìn)行配置的
7. axios攔截器
1.請(qǐng)求攔截器🔥
  • 在請(qǐng)求發(fā)出之前設(shè)置一些信息
//axios請(qǐng)求攔截器
axios.interceptors.request.use(function(config) {console.log(config.url)config.headers.mytoken = 'nihao';return config;
}, function(err){console.log(err)
})
//向服務(wù)器發(fā)起請(qǐng)求
axios.get('http://localhost:3000/adata').then(function(data){console.log(data)
})
2.響應(yīng)攔截器🔥
  • 在獲取數(shù)據(jù)之前對(duì)數(shù)據(jù)做一些加工處理

//axios響應(yīng)攔截器
axios.interceptors.response.use(function(res) {console.log(res)return res;
}, function(err){console.log(err)
})
//向服務(wù)器發(fā)起請(qǐng)求
axios.get('http://localhost:3000/adata').then(function (data) {console.log(data)
})
  1. (25行攔截器打印的信息 res)和 (31行最終需要的數(shù)據(jù) ) 打印的信息是完全一樣的。
  2. 但是,響應(yīng)攔截器res中拿到的不是具體數(shù)據(jù)
  • 在調(diào)用接口時(shí),只關(guān)心實(shí)際的數(shù)據(jù),不需要包裝數(shù)據(jù)的對(duì)象,可以在設(shè)置攔截器內(nèi)容,對(duì)接收到的數(shù)據(jù)進(jìn)行處理加工🔥
  • 最后拿到的data是經(jīng)過(guò)響應(yīng)攔截器處理后的數(shù)據(jù)
  • 注:文中部分內(nèi)容來(lái)源于網(wǎng)絡(luò),聯(lián)系侵刪
http://www.risenshineclean.com/news/51036.html

相關(guān)文章:

  • 展覽展示搭建設(shè)計(jì)化工seo顧問(wèn)
  • 設(shè)計(jì)必備網(wǎng)站網(wǎng)絡(luò)推廣營(yíng)銷方案免費(fèi)
  • 東莞做網(wǎng)站哪家最好網(wǎng)站模板建站公司
  • 谷歌網(wǎng)站統(tǒng)計(jì)壹起航網(wǎng)絡(luò)推廣的目標(biāo)
  • 公司網(wǎng)站建設(shè)合同書(shū)網(wǎng)絡(luò)推廣網(wǎng)站公司
  • 國(guó)家高新技術(shù)企業(yè)公示名單成都seo網(wǎng)站qq
  • 合肥 網(wǎng)站建設(shè)自媒體培訓(xùn)
  • 全市政府網(wǎng)站建設(shè)管理的講話seo推廣效果怎么樣
  • 做業(yè)務(wù)員找數(shù)據(jù)的網(wǎng)站網(wǎng)絡(luò)推廣app是違法的嗎
  • 建設(shè)企業(yè)官方網(wǎng)站的流程泉州搜索推廣
  • 吉首做網(wǎng)站中小企業(yè)網(wǎng)絡(luò)推廣
  • 做網(wǎng)站可以賺錢(qián)嗎知乎百度推廣電話客服
  • 深圳外貿(mào)建設(shè)網(wǎng)站網(wǎng)站建設(shè)步驟
  • 網(wǎng)站建設(shè)介紹nba最新交易一覽表
  • 網(wǎng)站建設(shè)如何復(fù)制鏈接網(wǎng)絡(luò)營(yíng)銷的重要性與意義
  • 無(wú)錫網(wǎng)站建設(shè)專家無(wú)錫網(wǎng)站制作福州網(wǎng)站排名推廣
  • 把excel做數(shù)據(jù)庫(kù)分享成網(wǎng)站2021百度模擬點(diǎn)擊工具
  • 網(wǎng)站維護(hù)合同模板百度推廣收費(fèi)標(biāo)準(zhǔn)
  • 一般建一個(gè)外貿(mào)網(wǎng)站多少錢(qián)百度關(guān)鍵詞優(yōu)化快速排名軟件
  • 網(wǎng)站招標(biāo)書(shū)怎么做香港seo公司
  • 有哪個(gè)網(wǎng)站可以做口腔執(zhí)業(yè)助理醫(yī)師題庫(kù)互聯(lián)網(wǎng)營(yíng)銷師培訓(xùn)課程
  • 現(xiàn)在網(wǎng)站建設(shè)還用測(cè)瀏覽器嗎企業(yè)培訓(xùn)課程安排表
  • 有多少網(wǎng)站是做廢舊信息的edm營(yíng)銷
  • 深圳做企業(yè)網(wǎng)站的公北京搜索引擎優(yōu)化
  • 網(wǎng)站為什么續(xù)費(fèi)域名??繛g覽器
  • app產(chǎn)品網(wǎng)站建設(shè)沈陽(yáng)線上教學(xué)
  • 制作視頻網(wǎng)站教程網(wǎng)站測(cè)速工具
  • 廣州建網(wǎng)站培訓(xùn)刷粉網(wǎng)站推廣馬上刷
  • 做國(guó)外購(gòu)物網(wǎng)站網(wǎng)上怎么找人去推廣廣告
  • 站長(zhǎng)素材網(wǎng)站種子搜索神器在線引擎