12/23/2025
Building a TikTok Dashboard with Nuxt 3 and TypeScript
A technical deep dive into structuring a maintainable API client using Vue Composables.
Introduction
Building a UI for data scraping requires state management, error handling, and type safety. In this guide, we will walk through how to architect a scalable useTikTokApi composable in Nuxt 3, based on the ZOCAILMINE SDK structure.
Concept: The Composable Pattern
Instead of scattering API calls across components, we encapsulate logic in a specific file (e.g., useTiktokApi.ts). This composable handles:
- State status (pending/loading/success),
result, anderror. - Configuration Selecting endpoints dynamically.
- Auth Injecting API keys automatically.
Structure Overview
| Component | Responsibility |
|---|---|
| State (Reactive) | Holds form data, results, and UI flags |
| Request Options | Maps dropdown selections to API endpoints |
| Execute Function | Centralized Axios call with error catching |
| Watcher | Resets state when the user changes request types |
Code Example: The Composable
Here is a simplified version of the reactive state pattern used in production:
import { reactive, toRefs } from 'vue';
export function useTikTokApi() {
// 1. Centralized State
const state = reactive({
status: 'pending',
result: null,
error: '',
form: { url: '', cursor: '0' }
});
// 2. The Execution Engine
async function executeApi(endpoint: string, apiKey: string) {
state.status = 'loading';
state.error = '';
try {
if (!apiKey) throw new Error("API Key Missing");
const payload = { url: state.form.url };
const response = await $fetch(endpoint, {
method: 'POST',
body: payload,
headers: { "x-api-key": apiKey }
});
state.status = 'success';
state.result = response;
} catch (err) {
state.status = 'error';
state.error = err.message || "API Error";
}
}
// 3. Expose to Components
return {
...toRefs(state),
executeApi
};
}