Senior
18 novembre 2026

Trova il bug: Vue.js / Nuxt.js

Uno snippet di codice. Trova il bug, o dimostra che non ce n'è.

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})

Clicca sulle righe che causano il problema.

Il tuo verdetto

Un tentativo al giorno. La risposta appare subito dopo.

Mantieni la tua serie

Crea un account per conservare la tua serie e seguire i tuoi progressi.

Crea un account