当前位置:   article > 正文

vue使用axios发送post请求(data为json格式)_前端axios post请求json格式入参

前端axios post请求json格式入参

安装axios

cnpm install axios
  • 1

在main.js中添加axios,此处注意axios插件不同于其他,引用不能使用Vue.use();而是使用Vue.prototype.$axios = axios;

import axios from 'axios'
Vue.prototype.$axios = axios;

new Vue({
  axios
})
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

在method中添加post方法

 Post()
    {
      if(this.username == "" || this.password == "")
      {
        alert("输入用户名或者密码")
      }
      else
      {
        this.$axios({
                 url: '',
                 method:'post',
                 //发送格式为json
                 data:JSON.stringify({func:'query',
                                      param:['3aa3a1fe7fe987945c8a097fa5274d352609b65021de4f0f0f8a4027479e802d']}),
//                 headers:
//                        {
//                          'Content-Type': 'application/json'
//                        }
               }).then(function(return_data)
        {
          alert(return_data)
        },function(return_data)
        {
          //alert(return_data)
        });
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/279927
推荐阅读
相关标签
  

闽ICP备14008679号