axios 测试post 请求出错 get 没问题, http 时 post也报错,请老师看一下

来源:4-3 axios基础介绍

好好学习丶4193290

2017-12-22

new Vue({
          el:'#vue',
          data () {
              return {
                  getData:'',
                  data:{
                    url:'/package.json',
                    data:{
                        id:234
                    },
                    method:'post',
                    params:{
                       
                    },
                    header:{
                        access_token:'sdsadasdsa'
                    }
                  }
              }
          },
          methods: {
              get(){
                axios.get('/package.json',{
                    params:{
                        id:123
                    },
                    headers:{
                        access_token:'123456778'
                    },
                    before:function(){
                        alert('请求开始')
                    }
                })
                   .then(res => {
                        console.log(res);
                        console.log(res.data)
                    }, error => {
                        console.log(error)
                        alert(error.response.statusText)
                    })
              },
              post(){
                axios.post('/package.json',{
                    id:22222
                },{
                    headers:{
                        access_token:'2ssssss'
                    }
                }).then(res => {

                }).catch(err => {

                })
              },
              http(){
                axios(this.data)
                    .then(res => {
                        console.log(res)
                    })
              }
          }
      })


写回答

1回答

河畔一角

2017-12-22

这个问题实际上并不是问题,post方式是需要向服务器提交内容的,你的提交地址是一个package.json文件,所以提交可能会有问题,真实的项目开发是不会有问题的。

0
0

Vue2.6+Node.js+MongoDB 全栈打造商城系统

课程全面升级,Vue2.6+Koa2,从前端入门全栈,让你的未来更宽广

2634 学习 · 924 问题

查看课程