我正在我的Angular应用程序中使用ngx-cookie-service模块来临时存储"用户名"或"userId"等用户相关信息.对于第一个try 登录该应用程序的用户来说,该应用程序运行良好.它从cookie中获取正确的用户名、用户ID等信息.然而,当其他用户随后try 登录时,尽管新用户的信息看起来像存储在cookie中,但http请求仍然使用前一用户的信息进行.如果我try 获取如下所示的userId信息,就会出现问题.
export class ImageService {
constructor(private http: HttpClient, private cookieService: CookieService) {
}
userId: number = +this.cookieService.get('user_id');
getImage(): Observable<Image> {
return this.http.get<Image>(imageUrlExample + this.userId);
}
}
但是,如果我从方法内的cookie中获取userId信息,则不会发生问题.
export class ImageService {
constructor(private http: HttpClient, private cookieService: CookieService) {
}
getImage(): Observable<Image> {
const userId: number = +this.cookieService.get('user_id');
return this.http.get<Image>(imageUrlExample + userId);
}
}
我认为这个问题可能会发生,因为缓存了index.html文件,但不知道如何清除Angular中的缓存.
顺便说一句,我使用NGINX作为Web服务器.如果有它的配置,不幸的是我找不到它.
我试图清除缓存index.html文件,但无法清除它,或者问题是因为其他原因而发生的.我还try 为缓存配置NGINX,但也没有成功.