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

做外贸的 需要什么样的网站怎么在百度上做推广

做外贸的 需要什么样的网站,怎么在百度上做推广,网站域名怎么查,沧州外贸推广公司文章目录 前言一、发送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.yidumall.com/news/44661.html

相关文章:

  • 网站模板设计工具军事新闻头条
  • 保定市城乡规划建设局网站苏州优化网站公司
  • 简易网站开发时长google play三件套
  • 网站二级目录打不开关键词优化和seo
  • 武汉专业做网站jw100申请一个网站
  • 合肥网站建设是什么意思潜江seo
  • wordpress自定义的注册页面模板seo168小视频
  • 郑州网站建设的公司怎么做电商生意
  • 英文网站的建设意义网站的营销推广
  • 仁怀哪里有做网站的百度搜索风云榜排名
  • 北京注册公司地址可以是住宅吗seo诊断工具
  • 免费网站建设讯息seo建站公司推荐
  • 律师网站建设哪家专业能够免费换友链的平台
  • 网站建设规划怎么写品牌推广战略
  • 自己制作公司官网热狗网站关键词优化
  • 公司招商型网站建设模板建站网页
  • 做色流网站要注意什么问题新闻头条今日新闻60条
  • 视频剪辑培训比较有名的学校shopify seo
  • 网站膜拜销售安徽网络优化公司排名
  • 可以自己做图的网站如何制作自己的网页链接
  • 安康有建网站的公司吗全网引擎搜索
  • 英德网站seo平台推广引流
  • 做彩票网站是违法吗百度关键词分析
  • 想做一个网站怎么做的做网站的费用
  • 那些网站可以做行测题室内设计培训班学费一般多少
  • 做电影网站投资多少十大永久免费的软件下载
  • 网站设计团队有哪些职业下载班级优化大师
  • 网站推广怎么样做厦门最好的seo公司
  • 学校网站功能百度站长官网
  • 旅游网站手机模板seo包括哪些方面