vue-axios-get/post

 安装axios

npm install axios -S

main.js中配置内容

import axios from 'axios'

页面中通过this.$axios调用

Vue.prototype.$axios = axios

配置qs解码(post)

import qs from 'qs'

Vue.prototype.$qs = qs

Get方式

this.$axios.get('url').then((res)=>{
  console.log(res)
})
.catch((error)=>{
  console.log(error)
})
post方式
let data = {
            id: id2,
            key: "houtai_beizhu",
            value: word,
          }
          this.$axios({
           method: 'post',
           url: '',
           data: this.$qs.stringify(data)
          }) 
          .then((res)=>{
            console.log(res)
          })
          .catch(function (error) {
                 console.log(error);
          });         
posted @ 2020-07-30 17:48  王霸道  阅读(99)  评论(0)    收藏  举报