顶针,星际猎手txt,北宋贼行天下
使用 post 请求
// global vue object vue.http.get('/someurl', [options]).then(successcallback, errorcallback); vue.http.post('/someurl', [body], [options]).then(successcallback, errorcallback); // in a vue instance this.$http.get('/someurl', [options]).then(successcallback, errorcallback); this.$http.post('/someurl', [body], [options]).then(successcallback, errorcallback);
然而,这并不代表使用过程中不会遇到问题:(比如使用时遇到这样的报错:xmlhttprequest cannot load xxx. response for preflight has invalid http status code 405);这个$http请求和jquery的ajax还是有点区别,这里的post的data默认不是以form data的形式,而是request payload。解决起来倒也很简单:在vue实例中添加headers字段:
http: { headers: {'content-type': 'application/x-www-form-urlencoded'} }
或者使用 vue 方面提供的更加简单做法:
vue.http.options.emulatejson = true;
总结
以上所述是小编给大家介绍的vue resource post请求时遇到的坑,希望对大家有所帮助
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
VUE+elementui组件在table-cell单元格中绘制微型echarts图
Vue通过getAction的finally来最大程度避免影响主数据呈现问题
vue 路由懒加载中给 Webpack Chunks 命名的方法
网友评论