2022.2.27 星期日 天气晴 今日学习目标:1.fetch 2.vue diff算法 key 3. vue computed 依赖收集
axios
★ Fetch
项目中怎么封装的fetch?Fetch超时怎么实现? promise写在哪里? settimeout写在哪里? 怎么取消Fetch请求或者怎么取消settimeout? axios怎么取消请求?
1.项目中怎么封装的fetch、axios?
好家伙,我的项目中明明封装的是axios,那么下面的内容就是封装axios
1.1 设置请求头
const apiInstance = axios.create({
headers: {
'X-Requested-With': 'XMLHttpRequest',
'Content-Type': 'application/x-www-form-urlencoded',
},
});
1.2 request
- post
if (config.method == "post") {
if (Object.prototype.toString.call(config.data) == "[object FormData]") {
config.data.append(key, data[key]);
} else {
// 用&链接
config.data = Object.keys(data).map((k) => {
return encodeURIComponent(k) + "=" + encodeURIComponent(data[k]);
}).join("&");
}
}
http [object FormData]的坑?
http content-type区别?
axios中post get 参数的区别?
- get
1.3 response