1. 快速变成 String 格式:
{ stamp: +new Date() }
2. 封装axios请求:
axios.get(this.URI, { params: { }, withCredentials: true //这里表示axios跨域请求携带 cookies }) .then(response => { let rst = response.data; if (rst.msg == '成功' && rst.code == '1000') { callback && callback(rst.rs); } else { errCallback && errCallback(); } }) .catch(error => { errCallback && errCallback(); });
且后端需要配置:
-
Access-Control-Allow-Origin
字段必须指定域名,不能为*
-
Access-Control-Allow-Credentials
为true