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