AntDesign Form使用布局相比传统Jquery有点繁琐ide
(一)先读写一个简单的input为例函数
<a-form :form="form" layout="vertical" hideRequiredMark> <a-row> <a-col :span="8"> <a-form-item label="用户名"> <a-input v-decorator="['username', {rules: [{ required: true, message: '用户名' }]}]" placeholder /> </a-form-item> ....
一、读数据,很简单布局
fileList: [{
uid: '-1',
name: 'xxx.png',
status: 'done',
url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png'
}]
二、下面是点击图片后自动上传写法,能够将action替换为你本身的上传图片后台地址测试
<a-row> <a-col :span="12"> <a-form-item label="图片"> <a-upload action="https://www.mocky.io/v2/5cc8019d300000980a055e76" listType="picture-card" :fileList="fileList" @preview="handlePreview" @change="handleChange" > <div v-if="fileList.length < 1"> <a-icon type="plus"/> <div class="ant-upload-text">上传图片</div> </div> </a-upload> </a-form-item> </a-col> </a-row>
handleCancel () { this.previewVisible = false }, handlePreview (file) { this.previewImage = file.url || file.thumbUrl this.previewVisible = true }, handleChange ({ fileList }) { this.fileList = fileList }
.ant-upload-select-picture-card i { font-size: 32px; color: #999; } .ant-upload-select-picture-card .ant-upload-text { margin-top: 8px; color: #666; }
三、当选择图片时已经自动调用action接口,后台返回数据以下ui
{
"name": "xxx.png",
"status": "done",
"url": "https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png",
"thumbUrl": "https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png"
}
四、到此时已经将图片上传到了服务上了,实际项目中须要同时上传token,就须要使用其余写法,等后续代码实现后将贴出来。this