老师幇我看看为啥老是报TypeError: Cannot read properties of undefined (reading 'then')
来源:9-1 商品详情交互实现

请眼熟我好吗
2022-07-27
vue3写的。
const methods = {
addCart() {
addProductCart({
productId: productId.value,
selected: true,
}).then((res = 0) => {
$store.dispatch("saveCartCount", res);
$router.push('/cart')
})
}
}
onMounted(() => {
productId.value = $route.params.id;
getProductInfo(productId.value).then((res) => {
productInfo.value = res;
});
})
return {
...methods,
$http.interceptors.response.use(
(response) => {
let res = response.data;
if (res.status == 0) {
return res.data;
} else if (res.status == 10) {
if (location.hash != "#/index") {
window.location.href = "/#/login";
}
return Promise.reject(res.msg);
} else {
return Promise.reject(res);
}
},
(error) => {
return Promise.reject(error);
}
);
报错:
runtime-core.esm-bundler.js?5c40:218 Uncaught TypeError: Cannot read properties of undefined (reading 'then')
at Proxy.addCart (Detail.vue?d0d1:143:1)
at Object.onClick._cache.<computed>._cache.<computed> (Detail.vue?d0d1:64:1)
at callWithErrorHandling (runtime-core.esm-bundler.js?5c40:155:1)
at callWithAsyncErrorHandling (runtime-core.esm-bundler.js?5c40:164:1)
at HTMLAnchorElement.invoker (runtime-dom.esm-bundler.js?830f:369:1)
addCart @ Detail.vue?d0d1:143
Object.onClick._cache.<computed>._cache.<computed> @ Detail.vue?d0d1:64
callWithErrorHandling @ runtime-core.esm-bundler.js?5c40:155
callWithAsyncErrorHandling @ runtime-core.esm-bundler.js?5c40:164
invoker @ runtime-dom.esm-bundler.js?830f:369
:8080/#/login:1 Uncaught (in promise) NEED_LOGIN
写回答
1回答
-
河畔一角
2022-07-28
看不懂,代码不够全面,无法定位问题,你可以在课程群找一下我。
00
相似问题