Senior
18 Kasım 2026

Hatayı bul: Vue.js / Nuxt.js

Tek bir kod parçası. Hatayı bul ya da hata olmadığını kanıtla.

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

Soruna yol açan satırlara tıkla.

Kararın

Günde bir deneme. Cevap hemen ardından görünür.

Serini koru

Serini korumak ve ilerlemeni takip etmek için hesap oluştur.

Hesap oluştur