np-upload Upload
A wrapper around n-upload that provides two-way binding of the file list via v-model.
The v-model value is of type string[], where each item is a JSON string of {name, url, type} by default. When listType is image-card and urlOnly is true, each item only stores the file's url string.
Basic Usage
Bind the file list with v-model and pass n-upload props through props.
Custom Upload Area
Customize the trigger area through the default slot, e.g. to implement image card upload with listType: 'image-card'.
urlOnly Mode
When listType is image-card, set urlOnly to true and the v-model value will be simplified to an array of url strings.
Component Configuration
Props
| Prop | Description | Type | Default |
|---|---|---|---|
| v-model | File list, each item is a JSON string of {name, url, type}; in urlOnly mode, each item is a url string | string[] | [] |
| urlOnly | Only effective when listType: 'image-card', v-model value is simplified to an array of url strings | boolean | false |
| props | NUpload props | NUpload Props | - |
| onChange | File list change event, first argument is the v-model value, second is the actual fileList | (value: string[], fileList: UploadFileInfo[]) => void | - |
Slots
| Slot | Description |
|---|---|
| default | Upload trigger area content |
Types
The component exports the following type definitions:
import type { NpUploadProps } from 'naive-plus'
Global Defaults
Use NpConfigProvider to change the props passed to n-upload (such as listType / accept / max / action). Props passed to the component itself always win.
Changing
listTypeat runtime does not re-parse the existingmodelValue: uploaded data is still parsed with thelistTypeused at initialization, so old-format data is never mistaken for the new format.
<np-config-provider
:component-options="{ Upload: { props: { listType: 'image-card' } } }"
>
<np-upload v-model="value" />
</np-config-provider>
