zoukankan      html  css  js  c++  java
  • ant-design-vue 之upload 文件上传

    ant-design-vue 之upload 文件上传

    01) 单文件上传

    使用  :before-upload="beforeUpload"  和  @change="handleChange"

    <template>
        <div>
            
            <div> 图片名字: {{imgName}}</div> <br /><br /><br />
            
            <a-upload
                    name="file"
                    :multiple="true"
                    :before-upload="beforeUpload"
                    :file-list="fileList"
                    @change="handleChange">
                <a-button> <a-icon type="upload" /> Click to Upload </a-button>
            </a-upload>
        </div>
    </template>
    <script>
        
        /* 这是ant-design-vue */
        import Vue from 'vue'
        import Antd, { message,Select } from 'ant-design-vue'  //这是ant-design-vue
        import 'ant-design-vue/dist/antd.css'
        Vue.use(Antd);
        /* 这是ant-design-vue */
    
        
        export default {
            components:{},
            data() {
                return {
                    imgName: "",
                    fileStatus: true,
                    fileList: [],
                }
            },
            methods: {
                
                beforeUpload(file) {
                    if (file.type !== 'image/jpeg') {
                        this.fileStatus = false;
                        this.$message.error('只能上传 JPG 格式');
                    }
                    this.imgName = file.name;
                    // 禁用原来上传,改用自定义上传,[ 必须返回false,才能在handleChange使用自己的请求方式]
                    return false; 
                },
                handleChange(info) {
                    if (this.fileStatus) {
                        // 开始上传
                        let fileList = [...info.fileList];
                        const formData = new FormData();
                        formData.append("file", fileList[0].originFileObj);
    
                        // this.$post("上传URL地址", formData).then(resUpLoadFiles => {
                        //     console.log(resUpLoadFiles);
                        // })
                        fileList = fileList.map(file => {
                            file.url = "https://www.cnblogs.com/images/jblogo.png";
                            return file;
                        });
                        this.fileList = fileList;
                    }
                },
            },
        };
    </script>
    
    <style scoped>
     
    </style>
    View Code

  • 相关阅读:
    Ubuntu VIM下实现python自动缩进
    认识Python和基础知识
    Linux常用服务器搭建
    VIM常用命令
    Linux基础
    LINUX操作系统VIM的安装和配置
    Ubuntu 16.04下安装搜狗输入法
    Ubuntu 16.04下sublime text3安装
    Ubuntu软件安装与卸载
    present(模态)实现出push的效果
  • 原文地址:https://www.cnblogs.com/dafei4/p/13582294.html
Copyright © 2011-2022 走看看