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

做一个网站需要多久制作网站第一步

做一个网站需要多久,制作网站第一步,建设网站和别人公司重名,seo网站改版文章目录 前言一、发送get请求二、发送post请求三、另一种写法总结 前言 今天学习Vue官方推荐的请求工具Axios ,Axios 是一个基于 promise 的 HTTP 库,可用于浏览器和 node.js 中。它简洁、易用且功能强大,支持多种请求类型(GET、…

文章目录

  • 前言
  • 一、发送get请求
  • 二、发送post请求
  • 三、另一种写法
  • 总结


前言

今天学习Vue官方推荐的请求工具Axios ,Axios 是一个基于 promise 的 HTTP 库,可用于浏览器和 node.js 中。它简洁、易用且功能强大,支持多种请求类型(GET、POST、PUT、DELETE 等),能够自动转换请求和响应数据(如JSON数据),并且提供了拦截请求和响应、取消请求、配置默认参数等多种功能,使得在进行 AJAX 请求时更加便捷和高效。


一、发送get请求

不多说了,直接实战示例,多看注释:


const axios = require('axios');// Make a request for a user with a given ID
axios.get('/user?ID=12345').then(function (response) {// handle successconsole.log(response);}).catch(function (error) {// handle errorconsole.log(error);}).finally(function () {// always executed});// Optionally the request above could also be done as
axios.get('/user', {params: {ID: 12345}}).then(function (response) {console.log(response);}).catch(function (error) {console.log(error);}).finally(function () {// always executed});  // Want to use async/await? Add the `async` keyword to your outer function/method.
async function getUser() {try {const response = await axios.get('/user?ID=12345');console.log(response);} catch (error) {console.error(error);}
}

二、发送post请求

示例:

axios.post('/user', {firstName: 'Fred',lastName: 'Flintstone'}).then(function (response) {console.log(response);}).catch(function (error) {console.log(error);});//表单作为参数:const {data} = await axios.post('/user', document.querySelector('#my-form'), {headers: {'Content-Type': 'application/json'}})//执行混合的请求:function getUserAccount() {return axios.get('/user/12345');}function getUserPermissions() {return axios.get('/user/12345/permissions');}const [acct, perm] = await Promise.all([getUserAccount(), getUserPermissions()]);// ORPromise.all([getUserAccount(), getUserPermissions()]).then(function ([acct, perm]) {// ...});// 表单文件相关:Multipart (multipart/form-data)  const {data} = await axios.post('https://httpbin.org/post', {firstName: 'Fred',lastName: 'Flintstone',orders: [1, 2, 3],photo: document.querySelector('#fileInput').files}, {headers: {'Content-Type': 'multipart/form-data'}})URL encoded form (application/x-www-form-urlencoded)const {data} = await axios.post('https://httpbin.org/post', {firstName: 'Fred',lastName: 'Flintstone',orders: [1, 2, 3]}, {headers: {'Content-Type': 'application/x-www-form-urlencoded'}})

三、另一种写法

代码如下(示例):

axios(config)
// Send a POST request
axios({method: 'post',url: '/user/12345',data: {firstName: 'Fred',lastName: 'Flintstone'}
});
// GET request for remote image in node.js
axios({method: 'get',url: 'http://bit.ly/2mTM3nY',responseType: 'stream'
}).then(function (response) {response.data.pipe(fs.createWriteStream('ada_lovelace.jpg'))});
axios(url[, config])
// Send a GET request (default method)这是最简单的默认方式,get请求
axios('/user/12345');
//Request method aliases
//For convenience aliases have been provided for all supported request methods. --别名axios.request(config)
axios.get(url[, config])
axios.delete(url[, config])
axios.head(url[, config])
axios.options(url[, config])
axios.post(url[, data[, config]])
axios.put(url[, data[, config]])
axios.patch(url[, data[, config]])
axios.postForm(url[, data[, config]])
axios.putForm(url[, data[, config]])
axios.patchForm(url[, data[, config]])

总结

Axios 因其灵活性和易用性,成为了现代前端开发中非常流行的HTTP库之一,广泛应用于各种Web项目中。今天内容比较多,需要大量时间实战测试和体会才能熟练应用。

http://www.yayakq.cn/news/257183/

相关文章:

  • 营销创意网站科技狂人
  • 好建网站建站行业最新消息
  • 淘宝装修做代码的网站腾讯云ADM怎么做网站
  • 如何建设网站简答题在百度搜索到自己的网站
  • 企业网站建设公司那家好怎么申请网站域名
  • 求职网站的建设方案咖啡公司网站建设策划书
  • 网站架构推荐公众号做图网站
  • 免费网站无需下载直接观看张掖网站建设培训
  • 南昌网站制作方案定制东莞公司网站建设公司哪家好
  • 绍兴网站建设方案托管怎么制作app软件教程
  • 购物网站系统建设方案西安十大网络公司
  • 手机网站页面如何制作直接可以秒玩的游戏
  • 产品设计五个流程南阳seo优化公司
  • django网站开发源代码自媒体平台注册入口账
  • 网页制作创建站点内容如何提升网站权重
  • 做网站的过程wordpress 在线商店
  • 大连网站建设比较好的公司wordpress ajax 参数
  • 北京 网站 外包小众电商平台有哪些
  • 企业网站seo排名优化wordpress主题验证失败
  • 外贸网站制作价格表界面设计心得
  • 建设一个网站多少钱上海最新发布
  • ps和dw 做网站做头像网站静态
  • 阴阳师网站怎么做58招聘求职找工作
  • 什么是网站开发技术中小型网站建设平台
  • 陕西省建设厅三类人员报名网站自己怎么做网站空间
  • 高端品牌网站建设集团青岛建站
  • 如何知道网站的字体怎么做网站的移动端适配版
  • 网站建设策划书ol网站和管理系统的区别
  • 重庆智能网站建设推荐做视频赚钱的国外网站
  • 石家庄网站外包公司商务信息网站