您好,登录后才能下订单哦!
密码登录
            
            
            
            
        登录注册
            
            
            
        点击 登录注册 即表示同意《亿速云用户服务条款》
        这篇文章主要介绍了Vue前端怎么实现与后端进行数据交互的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇Vue前端怎么实现与后端进行数据交互文章都会有所收获,下面我们一起来看看吧。
npm install axios --save
import Axios from 'axios';//后台交互 Vue.prototype.$http=Axios //defaults 设置全局默认路径 Axios.defaults.baseURL="/"
//第一种
this.$http.post('/index/customer/',{//里面写要传的值}).then(function(res) {
    // console.log('这是返回的客户数据');
    // console.log(res.data.data);
    this.customerArr = res.data.data
});//如果是get请求就把post换成get
//第二种,推荐使用该方法
this.$http({
                url: '/index/patchBase/',
                method: 'get',
                headers: { 'X-Requested-With': 'XMLHttpRequest' },
                params:{}//传值 如:params:{id:1,name:"gw"}
            }).then(res => {
                console.log('数据接收');
                console.log(res.data.data);
            });
this.$http({
                url: '/index/patchBase/',
                method: 'post',
                headers: { "Content-Type": "multipart/form-data" },
                data:{}//传值
            }).then(res => {
                console.log('数据接收');
                console.log(res.data.data);
            });需要注意的是 post、get请求的请求头数据不一样,传值方法不一样:get是params,post请求是用data传值














关于“Vue前端怎么实现与后端进行数据交互”这篇文章的内容就介绍到这里,感谢各位的阅读!相信大家对“Vue前端怎么实现与后端进行数据交互”知识都有一定的了解,大家如果还想学习更多知识,欢迎关注亿速云行业资讯频道。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。