zoukankan      html  css  js  c++  java
  • 单张图片上传,vue

    点击图片可可以实现上传

    <
    template> <div> <a-upload class="avatar-uploader" :showUploadList="false" :beforeUpload="beforeUpload" listType="picture-card" action="/amo/dist/picUpload" :headers="headers" @change="handleChange" > <img v-if="imageUrl" :src="imageUrl" alt="avatar" width="128" height="128" /> <div v-else> <a-icon :type="loading ? 'loading' : 'plus'" /> <div class="ant-upload-text">Upload</div> </div> </a-upload> </div> </template> <script> import { retriveMyDetail } from "@/api/information"; export default { data() { return { loading: false, imageUrl: "", headers: { Authorization: "Bearer" + this.$store.state.user.token } }; }, created() { this.getTableList(); }, methods: { getTableList() { this.spinning = false; retriveMyDetail().then(res => { this.imageUrl = res.data.qualificationPic1; }); }, handleChange(info) { if (info.file.status === "uploading") { this.loading = true; return; } if (info.file.status === "done") { this.imageUrl = info.file.response.data[0].filePath; this.loading = false; } }, //上传文件之前的钩子,参数为上传的文件,若返回 false 则停止上传。 beforeUpload(file) { const isJPG = file.type === "image/jpeg"; //判断上传文件格式 if (!isJPG) { this.$message.error("You can only upload JPG file!"); } const isLt2M = file.size / 1024 / 1024 < 5; //计算上传文件的大小 if (!isLt2M) { this.$message.error("Image must smaller than 5MB!"); } return isJPG && isLt2M; } } }; </script> <style> .avatar-uploader > .ant-upload { width: 128px; height: 128px; } .ant-upload-select-picture-card i { font-size: 32px; color: #999; } .ant-upload-select-picture-card .ant-upload-text { margin-top: 8px; color: #666; } </style>

  • 相关阅读:
    文本框小写变大写控制
    SQL2005 递归查询示例,非常方便
    GridView分页后进行添加,删除操作后,仍返回到当前页码
    从ASP.NET 1.1升级到ASP.NET 2.0要考虑的Cookie问题
    英语常用口语
    ASP.NET会话(Session)保存模式
    .NET2005文档自动生成
    JavaScript 弹出窗口总结
    SQL SERVER和SYBASE的渊源
    A versatile HDR Video Production System笔记
  • 原文地址:https://www.cnblogs.com/lvlvlv/p/11613213.html
Copyright © 2011-2022 走看看