我有一个模型商店类,其实例将导出如下:
<a :href="'/report/message/compose/' + student.StudentID">test</a>
稍后在我的Network模块类中解析来自axios的响应JSON:
export class CartStore {
...
}
export default new CartStore();
我正在使用cerialize
lib来反序列化import cartStore from "./CartStore"
...
export async function addToCart(timeslotId: number, quantity: number) {
return await axios.post(sprintf(Constants.ENDPOINT_ADD_TO_CART, {
"timeslot_id": timeslotId
}), { "quantity": quantity }, getConfig())
.then(res => {
let data = (res as AxiosResponse).data;
if (data != null) {
// **compilation error** below saying that "cannot assign to 'cartStore' because it is not a variable"
cartStore = Deserialize(data, CartStore); // <--
...
} else {
console.warn("[NetworkManager]", `null response when addToCart with timeslot id: ${timeslotId}`);
}
})
.catch(defaultErrorHandler);
}
到CartStore
。
默认情况下是导出的类实例Deserialize
吗?如何修复上述错误?
更新