码迷,mamicode.com
首页 > 其他好文 > 详细

vue---进行post和get请求

时间:2018-11-13 02:23:27      阅读:306      评论:0      收藏:0      [点我收藏+]

标签:参考   int   .net   error   vue   last   post请求   tst   方法   

参考文档:

https://www.jb51.net/article/125717.htm

使用axios

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

基本使用方法:

get请求:

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 
// Make a request for a user with a given ID
axios.get(‘/user?ID=12345‘)
 .then(function (response) {
  console.log(response);
 })
 .catch(function (error) {
  console.log(error);
 });
 
// 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);
 });
 

Post请求:

axios.post(‘/user‘, {
 firstName: ‘Fred‘,
 lastName: ‘Flintstone‘
})
.then(function (response) {
 console.log(response);
})
.catch(function (error) {
 console.log(error);
});

简单示例:

// 在进行 post 和 get 请求的时候,使用 axios 进行访问
// 进行 get 请求
axios.get(url).then(function (response){
    console.log(response);
}).catch(function(error){
    console.log(error);
});
// 进行post 请求            
axios.post(url,{firstName:‘Fred‘,lastName:‘Flintstone‘}).then(function (response) {
    console.log(response);
}).catch(function (error) {
    console.log(error);
});

 

vue---进行post和get请求

标签:参考   int   .net   error   vue   last   post请求   tst   方法   

原文地址:https://www.cnblogs.com/e0yu/p/9949857.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!