vue项目使用axios

使用:

npm install axios --save-dev

在main.js中import:

 

 

使用:

(1):POST方式

 1 let data= [{receiveAdd:receiveAddVal, sendAdd:sendAddVal,distance:distance,goodsName:goodsName,editname:editname,weight:weight,editnotename:editnotename,dataTime:dataTime,receiveName:receiveName,receiveSex:receiveSex,receiveTel:receiveTel,sendName:sendName,sendSex:sendSex,sendTel:sendTel,price:price}]
 2         this.$ajax({
 3           method: 'post',
 4           url: 'http://192.168.31.248:8080/sd_tech/PlaceOrder.do',
 5           dataType:'json',
 6           data:{
 7             dataDetail: JSON.stringify(data)
 8           }
 9         }).then(response=>{
10           alert('post code done')
11           this.$router.push({path:'/pay'})
12         }).catch(function(err){
13           console.log(err)
14         });

(2):GET方式

 1 <script>
 2 import $ from 'jquery'
 3 export default {
 4   name: 'totleOrder',
 5   data () {
 6     return {
 7       anylist: []
 8     }
 9   },
10   mounted () {
11     this.ready()
12   },
13   methods: {
14     ready: function () {
15       $.ajax({
16         type: 'GET',
17         url: './../../../static/total.json',
18         data: {},
19         dataType: 'json'
20       }).then(res => {
21         // console.log(res)
22         // console.log(res.data)   // console.log(res.data.length)就是获取到几条数据
23         this.anylist = res.data
24       })
25         .catch(error => {
26           console.log(error)
27         })
28     }
29   }
30 }
31 </script>

 

posted @ 2019-01-11 11:37  叶庚的博客  阅读(258)  评论(0编辑  收藏  举报