naive-ui/demo/documentation/components/upload/zhCN/controlled.md

70 lines
1.7 KiB
Markdown
Raw Normal View History

2020-02-18 19:24:45 +08:00
# 受控的文件列表
2020-02-18 20:09:34 +08:00
下面的例子纯属玩笑。
2020-02-18 19:24:45 +08:00
```html
<div>
2020-02-18 19:24:45 +08:00
<n-upload
action="http://www.mocky.io/v2/5e4bafc63100007100d8b70f"
:file-list="fileList"
@change="handleUploadChange"
:on-remove="handleRemove"
>
<n-button>上传文件</n-button>
</n-upload>
</div>
```
```js
export default {
data () {
return {
fileList: [
{
id: 'url-test',
name: 'URL 测试',
url: 'http://www.mocky.io/v2/5e4bafc63100007100d8b70f',
status: 'finished'
},
{
id: 'text-message',
name: '你的短信',
status: 'error',
},
{
id: 'notification',
name: '你的通知',
status: 'finished'
},
{
id: 'contact',
name: '你的联系人信息',
status: 'finished'
}
]
}
},
methods: {
handleUploadChange ({
fileList
}) {
this.fileList = fileList
},
2020-03-20 15:42:36 +08:00
handleRemove ({ file, fileList }) {
2020-02-18 19:24:45 +08:00
if (file.id === 'text-message') {
this.$NMessage.info('居然没传上去,算了,删了吧')
} else if (file.id === 'notification') {
this.$NMessage.error('不行,这个有用,不许删')
return false
} else if (file.id === 'contact') {
const message = this.$NMessage.loading('不知道这个有没有用,等我问问服务器能不能删', {
duration: 4000
})
return new Promise(resolve => {
setTimeout(() => {
this.$NMessage.error('不行,他们也不许删这个')
resolve(false)
}, 4000)
})
}
}
}
}
```