docs: update upload demo #753

pull/833/head
tangjinzhou 2019-05-25 18:24:22 +08:00
parent a5bb1918e5
commit 1790dab16b
16 changed files with 92 additions and 82 deletions

View File

@ -97,7 +97,7 @@ describe('Upload List', () => {
it('should be uploading when upload a file', done => { it('should be uploading when upload a file', done => {
const props = { const props = {
propsData: { propsData: {
action: 'http://jsonplaceholder.typicode.com/posts/', action: 'https://www.mocky.io/v2/5cc8019d300000980a055e76',
customRequest: successRequest, customRequest: successRequest,
}, },
listeners: { listeners: {
@ -133,7 +133,7 @@ describe('Upload List', () => {
it('handle error', done => { it('handle error', done => {
const props = { const props = {
propsData: { propsData: {
action: 'http://jsonplaceholder.typicode.com/posts/', action: 'https://www.mocky.io/v2/5cc8019d300000980a055e76',
customRequest: errorRequest, customRequest: errorRequest,
}, },
listeners: { listeners: {
@ -166,7 +166,7 @@ describe('Upload List', () => {
const handleChange = jest.fn(); const handleChange = jest.fn();
const props = { const props = {
propsData: { propsData: {
action: 'http://jsonplaceholder.typicode.com/posts/', action: 'https://www.mocky.io/v2/5cc8019d300000980a055e76',
listType: 'picture', listType: 'picture',
defaultFileList: fileList, defaultFileList: fileList,
beforeUpload: () => false, beforeUpload: () => false,

View File

@ -17,7 +17,7 @@ The return value of function `beforeUpload` can be a Promise to check asynchrono
listType="picture-card" listType="picture-card"
class="avatar-uploader" class="avatar-uploader"
:showUploadList="false" :showUploadList="false"
action="//jsonplaceholder.typicode.com/posts/" action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
:beforeUpload="beforeUpload" :beforeUpload="beforeUpload"
@change="handleChange" @change="handleChange"
> >

View File

@ -10,7 +10,7 @@ Classic mode. File selection dialog pops up when upload button is clicked.
```html ```html
<template> <template>
<a-upload name="file" :multiple="true" action="//jsonplaceholder.typicode.com/posts/" :headers="headers" @change="handleChange"> <a-upload name="file" :multiple="true" action="https://www.mocky.io/v2/5cc8019d300000980a055e76" :headers="headers" @change="handleChange">
<a-button> <a-button>
<a-icon type="upload" /> Click to Upload <a-icon type="upload" /> Click to Upload
</a-button> </a-button>

View File

@ -10,7 +10,7 @@ Use `defaultFileList` for uploaded files when page init.
```html ```html
<template> <template>
<a-upload action="//jsonplaceholder.typicode.com/posts/" :defaultFileList="defaultFileList"> <a-upload action="https://www.mocky.io/v2/5cc8019d300000980a055e76" :defaultFileList="defaultFileList">
<a-button> <a-button>
<a-icon type="upload" /> Upload <a-icon type="upload" /> Upload
</a-button> </a-button>

View File

@ -10,7 +10,7 @@ You can select and upload a whole directory.
```html ```html
<template> <template>
<a-upload action="//jsonplaceholder.typicode.com/posts/" directory> <a-upload action="https://www.mocky.io/v2/5cc8019d300000980a055e76" directory>
<a-button> <a-button>
<a-icon type="upload" /> Upload Directory <a-icon type="upload" /> Upload Directory
</a-button> </a-button>

View File

@ -11,7 +11,7 @@ Classic mode. File selection dialog pops up when upload button is clicked.
```html ```html
<template> <template>
<a-upload-dragger name="file" :multiple="true" action="//jsonplaceholder.typicode.com/posts/" @change="handleChange"> <a-upload-dragger name="file" :multiple="true" action="https://www.mocky.io/v2/5cc8019d300000980a055e76" @change="handleChange">
<p class="ant-upload-drag-icon"> <p class="ant-upload-drag-icon">
<a-icon type="inbox" /> <a-icon type="inbox" />
</p> </p>

View File

@ -16,7 +16,7 @@ You can gain full control over filelist by configuring `fileList`. You can accom
```html ```html
<template> <template>
<a-upload action="//jsonplaceholder.typicode.com/posts/" :multiple="true" :fileList="fileList" @change="handleChange"> <a-upload action="https://www.mocky.io/v2/5cc8019d300000980a055e76" :multiple="true" :fileList="fileList" @change="handleChange">
<a-button> <a-button>
<a-icon type="upload" /> Upload <a-icon type="upload" /> Upload
</a-button> </a-button>
@ -36,7 +36,7 @@ export default {
}, },
methods: { methods: {
handleChange(info) { handleChange(info) {
let fileList = info.fileList; let fileList = [...info.fileList];
// 1. Limit the number of uploaded files // 1. Limit the number of uploaded files
// Only to show two recent uploaded files, and old ones will be replaced by the new // Only to show two recent uploaded files, and old ones will be replaced by the new
@ -51,14 +51,6 @@ export default {
return file; return file;
}); });
// 3. filter successfully uploaded files according to response from server
fileList = fileList.filter((file) => {
if (file.response) {
return file.response.status === 'success';
}
return false;
});
this.fileList = fileList this.fileList = fileList
}, },
}, },

View File

@ -12,7 +12,7 @@ After users upload picture, the thumbnail will be shown in list. The upload butt
<template> <template>
<div class="clearfix"> <div class="clearfix">
<a-upload <a-upload
action="//jsonplaceholder.typicode.com/posts/" action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
listType="picture-card" listType="picture-card"
:fileList="fileList" :fileList="fileList"
@preview="handlePreview" @preview="handlePreview"

View File

@ -12,7 +12,7 @@ If uploaded file is a picture, the thumbnail can be shown. `IE8/9` do not suppor
<template> <template>
<div> <div>
<a-upload <a-upload
action="//jsonplaceholder.typicode.com/posts/" action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
listType="picture" listType="picture"
:defaultFileList="fileList" :defaultFileList="fileList"
> >
@ -23,7 +23,7 @@ If uploaded file is a picture, the thumbnail can be shown. `IE8/9` do not suppor
<br /> <br />
<br /> <br />
<a-upload <a-upload
action="//jsonplaceholder.typicode.com/posts/" action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
listType="picture" listType="picture"
:defaultFileList="fileList" :defaultFileList="fileList"
class="upload-list-inline" class="upload-list-inline"

View File

@ -61,7 +61,7 @@ export default {
// You can use any AJAX library you like // You can use any AJAX library you like
reqwest({ reqwest({
url: '//jsonplaceholder.typicode.com/posts/', url: 'https://www.mocky.io/v2/5cc8019d300000980a055e76',
method: 'post', method: 'post',
processData: false, processData: false,
data: formData, data: formData,

View File

@ -7,7 +7,7 @@ export default {
action: () => { action: () => {
return new Promise(resolve => { return new Promise(resolve => {
setTimeout(() => { setTimeout(() => {
resolve('//jsonplaceholder.typicode.com/posts/'); resolve('https://www.mocky.io/v2/5cc8019d300000980a055e76');
}, 2000); }, 2000);
}); });
}, },
@ -23,7 +23,9 @@ export default {
console.log('error', err); console.log('error', err);
}, },
}, },
style: { margin: '100px' }, style: {
margin: '100px',
},
}; };
return ( return (
<Upload {...uploaderProps}> <Upload {...uploaderProps}>

View File

@ -4,7 +4,7 @@ export default {
render() { render() {
const uploaderProps = { const uploaderProps = {
props: { props: {
action: '//jsonplaceholder.typicode.com/posts/', action: 'https://www.mocky.io/v2/5cc8019d300000980a055e76',
multiple: true, multiple: true,
beforeUpload(file, fileList) { beforeUpload(file, fileList) {
console.log(file, fileList); console.log(file, fileList);
@ -30,11 +30,9 @@ export default {
}, },
}; };
return ( return (
<div <div style={{
style={{ margin: '100px',
margin: '100px', }}>
}}
>
<div> <div>
<Upload {...uploaderProps}> <Upload {...uploaderProps}>
<a>开始上传</a> <a>开始上传</a>

View File

@ -5,9 +5,12 @@ export default {
render() { render() {
const uploaderProps = { const uploaderProps = {
props: { props: {
action: '//jsonplaceholder.typicode.com/posts/', action: 'https://www.mocky.io/v2/5cc8019d300000980a055e76',
multiple: false, multiple: false,
data: { a: 1, b: 2 }, data: {
a: 1,
b: 2,
},
headers: { headers: {
Authorization: '$prefix $token', Authorization: '$prefix $token',
}, },
@ -25,24 +28,25 @@ export default {
// EXAMPLE: post form-data with 'axios' // EXAMPLE: post form-data with 'axios'
const formData = new FormData(); const formData = new FormData();
if (data) { if (data) {
Object.keys(data).map(key => { Object
formData.append(key, data[key]); .keys(data)
}); .map(key => {
formData.append(key, data[key]);
});
} }
formData.append(filename, file); formData.append(filename, file);
axios axios.post(action, formData, {
.post(action, formData, { withCredentials,
withCredentials, headers,
headers, onUploadProgress: ({total, loaded}) => {
onUploadProgress: ({ total, loaded }) => { onProgress({
onProgress({ percent: Math.round((loaded / total) * 100).toFixed(2) }, file); percent: Math.round((loaded / total) * 100).toFixed(2),
}, }, file);
}) },
.then(({ data: response }) => { }).then(({data: response}) => {
onSuccess(response, file); onSuccess(response, file);
}) }).catch(onError);
.catch(onError);
return { return {
abort() { abort() {
@ -61,17 +65,17 @@ export default {
error(err) { error(err) {
console.log('error', err); console.log('error', err);
}, },
progress({ percent }, file) { progress({
percent,
}, file) {
console.log('progress', `${percent}%`, file.name); console.log('progress', `${percent}%`, file.name);
}, },
}, },
}; };
return ( return (
<div <div style={{
style={{ margin: '100px',
margin: '100px', }}>
}}
>
<div> <div>
<Upload {...uploaderProps}> <Upload {...uploaderProps}>
<a>开始上传</a> <a>开始上传</a>

View File

@ -4,8 +4,11 @@ export default {
render() { render() {
const uploaderProps = { const uploaderProps = {
props: { props: {
action: '//jsonplaceholder.typicode.com/posts/', action: 'https://www.mocky.io/v2/5cc8019d300000980a055e76',
data: { a: 1, b: 2 }, data: {
a: 1,
b: 2,
},
headers: { headers: {
Authorization: 'xxxxxxx', Authorization: 'xxxxxxx',
}, },
@ -28,7 +31,9 @@ export default {
console.log('error', err); console.log('error', err);
}, },
}, },
style: { margin: '100px' }, style: {
margin: '100px',
},
}; };
return ( return (
<Upload {...uploaderProps}> <Upload {...uploaderProps}>

View File

@ -4,7 +4,7 @@ export default {
render() { render() {
const uploaderProps = { const uploaderProps = {
props: { props: {
action: '//jsonplaceholder.typicode.com/posts/', action: 'https://www.mocky.io/v2/5cc8019d300000980a055e76',
type: 'drag', type: 'drag',
accept: '.png', accept: '.png',
beforeUpload(file) { beforeUpload(file) {
@ -29,8 +29,13 @@ export default {
alert('click'); alert('click');
}, },
}, },
style: { display: 'inline-block', width: '200px', height: '200px', background: '#eee' }, style: {
display: 'inline-block',
width: '200px',
height: '200px',
background: '#eee',
},
}; };
return <Upload {...uploaderProps} />; return <Upload {...uploaderProps}/>;
}, },
}; };

View File

@ -2,11 +2,9 @@ import Upload from '../index';
export default { export default {
data() { data() {
return { return {destroyed: false};
destroyed: false,
};
}, },
methods: { methods : {
destroy() { destroy() {
this.destroyed = true; this.destroyed = true;
}, },
@ -16,8 +14,11 @@ export default {
return null; return null;
} }
const propsObj = { const propsObj = {
action: '//jsonplaceholder.typicode.com/posts/', action: 'https://www.mocky.io/v2/5cc8019d300000980a055e76',
data: { a: 1, b: 2 }, data: {
a: 1,
b: 2,
},
headers: { headers: {
Authorization: 'xxxxxxx', Authorization: 'xxxxxxx',
}, },
@ -63,14 +64,15 @@ export default {
opacity:0.5; opacity:0.5;
`; `;
return ( return (
<div <div style={{
style={{ margin: '100px',
margin: '100px', }}>
}}
>
<h2>固定位置</h2> <h2>固定位置</h2>
<style>{style}</style> <style>
{
style
}</style>
<div> <div>
<Upload {...uploaderProps}> <Upload {...uploaderProps}>
@ -82,17 +84,19 @@ export default {
<div <div
style={{ style={{
height: '200px', height: '200px',
overflow: 'auto', overflow: 'auto',
border: '1px solid red', border: '1px solid red',
}} }}>
> <div style={{
<div height: '500px',
style={{ }}>
height: '500px', <Upload
}} {...uploaderProps1}
> component="div"
<Upload {...uploaderProps1} component="div" style={{ display: 'inline-block' }}> style={{
display: 'inline-block',
}}>
<a>开始上传2</a> <a>开始上传2</a>
</Upload> </Upload>
</div> </div>