axios发送post请求

安装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
})

在method中添加post方法

Post()
{
if(this.username ==== “”)
{
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)
附上博文链接!

猜你喜欢

转载自blog.csdn.net/weixin_44275692/article/details/89924269