改成这样,增加一个 Vue.http.interceptors.push
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/vue@2.6.1.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/vue-resource.min.js"></script>
</head>
<body>
<div id="app">
</div>
<script type="text/javascript">
Vue.http.interceptors.push((request, next) => {
//request.credentials = true; // 接口每次请求会跨域携带COOKIE
//request.method= 'POST'; // 请求方式(get,post)
//request.headers.set('token','111') // 请求headers携带参数
// console.log(this)//此处this为请求所在页面的Vue实例
// modify request
request.method = 'GET'; //在请求之前可以进行一些预处理和配置
next((response) => {
if (!response.ok) {
response.ok=true;//如果http接口不是返回的http状态200,我们手动矫正一下,否则就无法执行$http里的第一个回调了
}
//在响应之后传给then之前对response进行修改和逻辑判断。对于token时候已过期的判断,就添加在此处,页面中任何一次http请求都会先调用此处方法,也可以修改response的内容
response.status = 200;
response.body = "hi";
return response;
});
});
var vm = new Vue({
el: '#app',
data: {},
mounted: function() {
this.$http.post('api',
{
params: {
a: 1,
b: 2
}}).then(function(res) {
document.write(res.body);
},
function(res) {
console.log(res.status);
});
},
methods: {}
})
</script>
</body>
</html>
网友回复
阿里云ESA、cloudflare worker、腾讯云EdgeOne网站代理托管哪家更好?
剪映能打开.fcpxml格式的文件吗?
增量式编码器与绝对式编码器的区别是啥?
有没有开源的单张照片或者序列帧图片或视频就能重建4d场景动画项目?
chrome网页突然报错:错误代码:RESULT_CODE_KILLED_BAD_MESSAGE
openai的codex如何全程无需手动确认自动修改文件?
阿里云oss前端上传文件直传如何限制文件类型?
阿里云oss前端获取policy签名直传oss上传文件回调如何传?
如何将根据三维物体通过提示词变成可交互的4d场景动画?
浏览器中实时摄像头离线视觉ai模型有吗?


