vue怎么使用七牛?
发布于 1年前 作者 hejing 3899 次浏览 来自 问答

1.npm install qiniu

  1. 在main.js和qiniu.vue中都试过了import Qiniu from ‘qiniu’

但还是调用了之后还是报错 Qiniu is not defined

<template>
    <div id="container" style="position: relative;">
        <a class="btn btn-default btn-lg " id="pickfiles" href="#" style="position: relative; z-index: 1;">
            <i class="glyphicon glyphicon-plus"></i>
            <span>选择文件</span>
        </a>
        <div id="html5_1b9icn8ud1gvp1ev1tko1e7v17kv3_container" class="moxie-shim moxie-shim-html5" style="position: absolute; top: 0px; left: 0px; width: 171px; height: 46px; overflow: hidden; z-index: 0;">
            <input id="html5_1b9icn8ud1gvp1ev1tko1e7v17kv3" type="file" style="font-size: 999px; opacity: 0; position: absolute; top: 0px; left: 0px; width: 100%; height: 100%;" multiple="" accept="">
        </div>
    </div>
</template>
<script>
import Qiniu from './qiniu'
export default{
    mounted(){
        var uploader = new Qiniu.uploader({
            runtimes: 'html5,flash,html4',
            browse_button: 'pickfiles',
            max_file_size: '100mb',
            flash_swf_url: 'js/plupload/Moxie.swf',
            dragdrop: true,
            chunk_size: '4mb',
            //uptoken_url: adminUrl+"uptoken/test",
            uptoken_url: '/house/qiniu/test',
            save_key: true,
            domain: 'http://7xlpa2.com2.z0.glb.qiniucdn.com/',
            auto_start: true,
            init: {
                'FilesAdded': function (up, files) {
                },
                'BeforeUpload': function (up, file) {
                },
                'UploadProgress': function (up, file) {
                },
                'UploadComplete': function () {
                },
                'FileUploaded': function (up, file, info) { 
                    console.log(info)

                },
                'Error': function (up, err, errTip) {
                    if (err.status == 400) {
                        alert('请求报文格式错误,报文构造不正确或者没有完整发送。')
                    } else if (err.status == 401) {
                        alert('上传凭证无效。')
                    } else if (err.status == 413) {
                        alert('上传内容长度大于 fsizeLimit 中指定的长度限制。。')
                    } else if (err.status == 579) {
                        alert('回调业务服务器失败。')
                    } else if (err.status == 599) {
                        alert('七牛服务端操作失败。')
                    }
                    else if (err.status == 614) {
                        alert('目标资源已存在。')
                    }
                }
            }
        });
    },
    created: function(){
        
    }
}
</script>
\n``
回到顶部