Module Configuration
Introduction
Movk Nuxt uses movk as the configuration key in nuxt.config.ts:
Prefix
- Type:
string - Default:
'M'
Component prefix, used to avoid naming conflicts with other component libraries.
export default defineNuxtConfig({
movk: {
prefix: 'My' // Components become MyAutoForm, MyDatePicker, etc.
}
})
Theme
The theme module centrally manages colors, radius, fonts and icon sets, and provides options to the ThemePicker component and useTheme composable. All fields are configured under movk.theme.
ThemePicker component.export default defineNuxtConfig({
movk: {
theme: {
enabled: true
}
}
})
appConfig defaults, theme plugin, ThemePicker component registration). Defaults to true. When disabled, ThemePicker is no longer registered.@nuxt/ui's theme.colors. Defaults to ['primary', 'secondary', 'success', 'info', 'warning', 'error'].@nuxt/ui's theme.defaultVariants.@nuxt/ui's theme.prefix. For example 'tw'.ThemePicker font options; when provided, completely replaces the built-in list. Each item is { name, href? }, where href falls back to Google Fonts at runtime if omitted.font-family and the selector label.'https://cdn.mhaibaraai.cn/fonts/alibaba-puhuiti.css'. Falls back to Google Fonts based on name if omitted.ThemePicker radius options (in rem). Defaults to [0, 0.125, 0.25, 0.375, 0.5].ThemePicker neutral color options.Custom Font Options
export default defineNuxtConfig({
movk: {
theme: {
fonts: [
{ name: 'Alibaba PuHuiTi', href: 'https://cdn.mhaibaraai.cn/fonts/alibaba-puhuiti.css' },
{ name: 'Inter' } // No href, falls back to Google Fonts
]
}
}
})
API
The API system provides complete request wrapping and auth management, configured via the api option.
Basic Configuration
export default defineNuxtConfig({
movk: {
api: {
// Whether to enable API functionality
enabled: true,
// Default endpoint name
defaultEndpoint: 'default',
// Whether to enable debug mode
debug: false
}
}
})
true.'default'.false.endpoints
Supports configuring multiple API endpoints, each with its own independent configuration:
export default defineNuxtConfig({
movk: {
api: {
endpoints: {
// Default endpoint
default: {
baseURL: '/api'
},
// Admin endpoint
admin: {
baseURL: '/admin-api',
auth: {
tokenType: 'Bearer'
}
},
// Third-party API
external: {
baseURL: 'https://api.example.com',
headers: {
'X-API-Key': 'your-api-key'
}
}
}
}
}
})
Endpoint Options
auth
Configure automatic auth behavior, integrated with nuxt-auth-utils:
export default defineNuxtConfig({
movk: {
api: {
auth: {
// Enable auth
enabled: true,
// Token source
tokenSource: 'session',
// Path to token in session
sessionTokenPath: 'user.accessToken',
// Token type
tokenType: 'Bearer',
// Header name
headerName: 'Authorization',
// 401 unauthorized handling config
unauthorized: {
// Redirect to login page on 401
redirect: true,
loginPath: '/login',
// Clear session on 401
clearSession: true
}
}
}
}
})
Auth Options
false.'session'.'token' maps to session.token, 'user.token' maps to session.user.token. Defaults to 'token'.'Bearer'.tokenType is 'Custom'.'Authorization'.true.'/login'.true.response
Configure API response parsing rules, including business status code determination, data unwrapping fields and message extraction:
export default defineNuxtConfig({
movk: {
api: {
response: {
// Successful status code list
successCodes: [200, 0],
// Status code field name
codeKey: 'code',
// Message field name
messageKey: 'message',
// Data field name
dataKey: 'data'
}
}
}
})
Response Configuration Options
code value in the response is considered successful if it is in this list. Defaults to [200, 0].'code'.'message'.'data'.toast
Configure global Toast notification behavior:
export default defineNuxtConfig({
movk: {
api: {
toast: {
// Enable notifications globally
enabled: true,
// Success notification config
success: {
show: true,
color: 'success',
duration: 3000
},
// Error notification config
error: {
show: true,
color: 'error',
duration: 3000
}
}
}
}
})
Toast Options
true.Configuration Priority
Configuration is merged in the following priority order (later overrides earlier):
- Module built-in defaults - Default config defined in
api-defaults.ts - Global config -
movk.api.auth,movk.api.toast,movk.api.response - Endpoint config -
movk.api.endpoints[name].auth, etc. - Request-level config -
toastoption inuseApiFetch, etc.
// Example: request-level config overrides global config
const { data } = await useApiFetch('/users', {
toast: {
successMessage: 'Fetched successfully', // Overrides global config
error: false // Disable error notifications
}
})
Environment Variables
For sensitive configuration (such as API keys), use environment variables:
export default defineNuxtConfig({
movk: {
api: {
endpoints: {
external: {
baseURL: process.env.EXTERNAL_API_URL,
headers: {
'X-API-Key': process.env.EXTERNAL_API_KEY
}
}
}
}
}
})
EXTERNAL_API_URL=https://api.example.com
EXTERNAL_API_KEY=your-api-key