Upload.vue 3.9 KB
Newer Older
L
lin-xin 已提交
1 2 3 4 5 6 7 8
<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item><i class="el-icon-date"></i> 表单</el-breadcrumb-item>
                <el-breadcrumb-item>图片上传</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
L
lin-xin 已提交
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
        <div class="content-title">支持拖拽</div>
        <div class="plugins-tips">
            Element UI自带上传组件。
            访问地址:<a href="http://element.eleme.io/#/zh-CN/component/upload" target="_blank">Element UI Upload</a>
        </div>
        <el-upload
                action="/api/posts/"
                type="drag"
                :thumbnail-mode="true"
                :on-preview="handlePreview"
                :on-remove="handleRemove"
                :on-error="handleError"
                :default-file-list="fileList"
        >
            <i class="el-icon-upload"></i>
            <div class="el-dragger__text">将文件拖到此处,或<em>点击上传</em></div>
            <div class="el-upload__tip" slot="tip">只能上传jpg/png文件,且不超过500kb</div>
        </el-upload>
        <div class="content-title">支持裁剪</div>
L
lin-xin 已提交
28 29 30 31 32 33 34 35 36 37
        <div class="plugins-tips">
            Vue-Core-Image-Upload:一款轻量级的vue上传插件,支持裁剪。
            访问地址:<a href="https://github.com/Vanthink-UED/vue-core-image-upload" target="_blank">Vue-Core-Image-Upload</a>
        </div>
        <img class="pre-img" :src="src" alt="">
        <vue-core-image-upload :class="['pure-button','pure-button-primary','js-btn-crop']"
                               :crop="true"
                               text="上传图片"
                               url="/api/posts/"
                               extensions="png,gif,jpeg,jpg"
L
lin-xin 已提交
38 39
                               @:imageuploaded="imageuploaded"
                               @:errorhandle="handleError"></vue-core-image-upload>
L
lin-xin 已提交
40 41 42 43 44 45 46 47 48
    </div>
</template>

<script>
    import VueCoreImageUpload  from 'vue-core-image-upload';
    export default {
        data: function(){
            return {
                src: '../../../static/img/img.jpg',
L
lin-xin 已提交
49
                fileList: []
L
lin-xin 已提交
50 51 52 53 54 55 56 57 58
            }
        },
        components: {
            VueCoreImageUpload
        },
        methods:{
            imageuploaded(res) {
                console.log(res)
            },
L
lin-xin 已提交
59 60 61 62 63 64 65 66 67 68 69 70
            handleRemove(file, fileList) {
                console.log(file, fileList);
            },
            handlePreview(file) {
                console.log(file);
            },
            handleError(){
                this.$notify.error({
                    title: '上传失败',
                    message: '图片上传接口上传失败,可更改为自己的服务器接口'
                });
            }
L
lin-xin 已提交
71 72 73 74 75
        }
    }
</script>

<style>
L
lin-xin 已提交
76 77 78 79 80 81 82
    .content-title{
        font-weight: 400;
        line-height: 50px;
        margin: 10px 0;
        font-size: 22px;
        color: #1f2f3d;
    }
L
lin-xin 已提交
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
    .pre-img{
        width:250px;
        height: 250px;
        margin-bottom: 20px;
    }
    .pure-button{
        width:150px;
        height:40px;
        line-height: 40px;
        text-align: center;
        background: #00a2ff;
        color: #fff;
        border-radius: 3px;
    }
    .g-core-image-corp-container .info-aside{
        height:45px;
    }
L
lin-xin 已提交
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
    .el-upload--text {
        background-color: #fff;
        border: 1px dashed #d9d9d9;
        border-radius: 6px;
        box-sizing: border-box;
        width: 360px;
        height: 180px;
        text-align: center;
        cursor: pointer;
        position: relative;
        overflow: hidden;
    }
    .el-upload--text .el-icon-upload {
        font-size: 67px;
        color: #97a8be;
        margin: 40px 0 16px;
        line-height: 50px;
    }
    .el-upload--text {
        color: #97a8be;
        font-size: 14px;
        text-align: center;
    }
    .el-upload--text em {
        color: #20a0ff;
        font-style: normal;
    }
L
lin-xin 已提交
127
</style>