# Smart-Tagz with Nuxt 3 Guide
Complete guide for integrating Smart-Tagz with Nuxt 3.
## Installation
### Option 1: As a Nuxt Module (Recommended)
The easiest way to use Smart-Tagz in Nuxt 3 is through the official module.
```bash
npm install smart-tagz
# or
pnpm add smart-tagz
# or
yarn add smart-tagz
```
Add to your `nuxt.config.ts`:
```typescript
export default defineNuxtConfig({
modules: [
'smart-tagz/nuxt'
]
})
```
### Option 2: Manual Installation
If you prefer manual setup:
```bash
npm install smart-tagz
```
Create a plugin file `plugins/smart-tagz.ts`:
```typescript
import { defineNuxtPlugin } from '#app'
import SmartTagz from 'smart-tagz'
export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.vueApp.component('SmartTagz', SmartTagz)
})
```
Add to `nuxt.config.ts`:
```typescript
export default defineNuxtConfig({
plugins: ['~/plugins/smart-tagz.ts']
})
```
---
## Basic Usage
Once installed, use the component anywhere in your Nuxt 3 app:
```vue
Selected: {{ selectedTags }}
```
---
## Common Patterns
### 1. Programmatic Tag Management
Access the component instance to add/clear tags programmatically:
```vue
```
### 3. Async Data Loading
Load tags from an API:
```vue
Loading...
```
### 4. Form Integration
Use with Nuxt form validation:
```vue
```
---
## Props Reference
Here are the main props you'll use in Nuxt 3:
```typescript
interface SmartTagzProps {
// Display
inputPlaceholder?: string // Default: 'Enter tag...'
maxTags?: number // Maximum tags allowed
// Data
defaultTags?: string[] // Initial tags
sources?: string[] // Autocomplete options
// Behavior
editable?: boolean // Allow editing existing tags
allowDuplicates?: boolean // Allow duplicate tags
autosuggest?: boolean // Show suggestions
allowPaste?: { delimiter: string } // Allow pasting with delimiter
quickDelete?: boolean // Allow quick delete with keyboard
// Events
onChanged?: (tags: string[]) => void // Fired when tags change
}
```
---
## Events and Methods
### Using the `onChanged` Event
```vue
```
### Accessing Component Methods
Via template ref:
```typescript
const tagsRef = ref()
// Add a tag programmatically
tagsRef.value.handleAddTag('new-tag')
// Remove a tag
tagsRef.value.handleRemoveTag('tag-id')
```
---
## Styling in Nuxt 3
Smart-Tagz comes with default styles. Customize them in your app:
### Global Overrides
In your main layout or app component:
```vue
```
### Component-Level Styles
```vue
```
---
## TypeScript Support
Smart-Tagz is fully typed for Nuxt 3:
```vue
```
---
## Troubleshooting
### Issue: Component not found
**Solution**: Ensure the module is added to `nuxt.config.ts`:
```typescript
export default defineNuxtConfig({
modules: ['smart-tagz/nuxt']
})
```
### Issue: Styles not loading
**Solution**: Make sure SCSS is configured:
```typescript
export default defineNuxtConfig({
modules: ['smart-tagz/nuxt'],
vite: {
css: {
preprocessorOptions: {
scss: {},
},
},
},
})
```
### Issue: SSR Hydration Mismatch
**Solution**: Wrap component with ``:
```vue
```
---
## Complete Example
See `/examples/Nuxt3Example.vue` for a complete working example with:
- Basic usage
- Editable tags
- Dynamic sources
- Programmatic control
- All available features
---
## Performance Tips
1. **Memoize large source arrays**:
```typescript
const largeSource = computed(() =>
expensiveFunction(sourceData)
)
```
2. **Use lazy loading for async sources**:
```typescript
const tags = await $fetch('/api/tags')
```
3. **Limit suggestions with max-tags**:
```vue
```
---
## Support
For issues or questions:
- [GitHub Issues](https://github.com/prabhuignoto/smart-tagz/issues)
- [Documentation](https://github.com/prabhuignoto/smart-tagz)
---
## Next Steps
- Check out the [main documentation](../README.md)
- Review [API reference](../docs)
- Explore [examples](../examples)