Senior
18 listopada 2026

Znajdź błąd: Vue.js / Nuxt.js

Jeden fragment kodu. Znajdź błąd albo udowodnij, że go nie ma.

typescript
1// services/apiClient.ts
2class ApiClient {
3  private static instance: ApiClient
4  private token: string | null = null
5
6  static getInstance() {
7    if (!ApiClient.instance) ApiClient.instance = new ApiClient()
8    return ApiClient.instance
9  }
10
11  setToken(token: string) { this.token = token }
12  getToken() { return this.token }
13}
14
15// plugins/api.ts (Nuxt SSR)
16export default defineNuxtPlugin(() => {
17  const client = ApiClient.getInstance()
18  const token = useCookie('token').value
19  if (token) client.setToken(token)
20  return { provide: { api: client } }
21})

Kliknij linie, które powodują problem.

Twój werdykt

Jedna próba dziennie. Odpowiedź pojawi się od razu potem.

Zachowaj swoją serię

Załóż konto, aby zachować serię i śledzić postępy.

Załóż konto