体验新版 GitCode,发现更多精彩内容 >>
webpackJsonp([3],{ZIr9:function(s,t,a){var v=a("VU/8")(null,a("iC+2"),null,null,null);s.exports=v.exports},dSBi:function(s,t,a){s.exports=a("ZIr9")},"iC+2":function(s,t){s.exports={render:function(){var s=this,t=s.$createElement,a=s._self._c||t;return a("section",[a("h2",{attrs:{id:"Upload组件"}},[a("a",{staticClass:"anchor",attrs:{href:"#cube-Upload组件-anchor","aria-hidden":"true"}},[a("svg",{attrs:{"aria-hidden":"true",height:"16",version:"1.1",viewBox:"0 0 16 16",width:"16"}},[a("path",{attrs:{"fill-rule":"evenodd",d:"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"}})])]),s._v(" Upload 组件")]),s._v(" "),s._m(0),s._v(" "),s._m(1),s._v(" "),s._m(2),s._v(" "),s._m(3),s._v(" "),a("h3",{attrs:{id:"示例"}},[a("a",{staticClass:"anchor",attrs:{href:"#cube-示例-anchor","aria-hidden":"true"}},[a("svg",{attrs:{"aria-hidden":"true",height:"16",version:"1.1",viewBox:"0 0 16 16",width:"16"}},[a("path",{attrs:{"fill-rule":"evenodd",d:"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"}})])]),s._v(" 示例")]),s._v(" "),s._m(4),s._v(" "),a("h3",{attrs:{id:"Props配置"}},[a("a",{staticClass:"anchor",attrs:{href:"#cube-Props配置-anchor","aria-hidden":"true"}},[a("svg",{attrs:{"aria-hidden":"true",height:"16",version:"1.1",viewBox:"0 0 16 16",width:"16"}},[a("path",{attrs:{"fill-rule":"evenodd",d:"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"}})])]),s._v(" Props 配置")]),s._v(" "),s._m(5),s._v(" "),s._m(6),s._v(" "),s._m(7),s._v(" "),s._m(8),s._v(" "),s._m(9),s._v(" "),s._m(10),s._v(" "),a("h3",{attrs:{id:"事件"}},[a("a",{staticClass:"anchor",attrs:{href:"#cube-事件-anchor","aria-hidden":"true"}},[a("svg",{attrs:{"aria-hidden":"true",height:"16",version:"1.1",viewBox:"0 0 16 16",width:"16"}},[a("path",{attrs:{"fill-rule":"evenodd",d:"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"}})])]),s._v(" 事件")]),s._v(" "),s._m(11),s._v(" "),a("h3",{attrs:{id:"实例方法"}},[a("a",{staticClass:"anchor",attrs:{href:"#cube-实例方法-anchor","aria-hidden":"true"}},[a("svg",{attrs:{"aria-hidden":"true",height:"16",version:"1.1",viewBox:"0 0 16 16",width:"16"}},[a("path",{attrs:{"fill-rule":"evenodd",d:"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"}})])]),s._v(" 实例方法")]),s._v(" "),s._m(12)])},staticRenderFns:[function(){var s=this,t=s.$createElement,a=s._self._c||t;return a("blockquote",[a("p",[s._v("1.3.0 新增")])])},function(){var s=this,t=s.$createElement,a=s._self._c||t;return a("p",[a("code",{pre:!0},[s._v("Upload")]),s._v(" 上传组件。")])},function(){var s=this,t=s.$createElement,a=s._self._c||t;return a("p",[a("strong",[s._v("注:")]),s._v(" 本文中所有的原始文件对象统称为"),a("strong",[s._v("原始文件")]),s._v(",而经过包装后的文件对象称为"),a("strong",[s._v("文件对象")]),s._v(",这个文件对象的结构如下:")])},function(){var s=this,t=s.$createElement,a=s._self._c||t;return a("table",[a("thead",[a("tr",[a("th",[s._v("属性")]),s._v(" "),a("th",[s._v("说明")]),s._v(" "),a("th",[s._v("类型")])])]),s._v(" "),a("tbody",[a("tr",[a("td",[s._v("name")]),s._v(" "),a("td",[s._v("文件名")]),s._v(" "),a("td",[s._v("String")])]),s._v(" "),a("tr",[a("td",[s._v("size")]),s._v(" "),a("td",[s._v("文件大小")]),s._v(" "),a("td",[s._v("Number")])]),s._v(" "),a("tr",[a("td",[s._v("url")]),s._v(" "),a("td",[s._v("文件 url,通过 URL.createObjectURL 获得")]),s._v(" "),a("td",[s._v("String")])]),s._v(" "),a("tr",[a("td",[s._v("base64")]),s._v(" "),a("td",[s._v("文件 base64 的值,这个会从原始文件的 base64 属性获得(默认是没有的,但是插件可以添加,例如下边演示的压缩 compress 插件就会添加 base64 值)")]),s._v(" "),a("td",[s._v("String")])]),s._v(" "),a("tr",[a("td",[s._v("status")]),s._v(" "),a("td",[s._v("文件状态,包含四个: ready, uploading, success, error")]),s._v(" "),a("td",[s._v("String")])]),s._v(" "),a("tr",[a("td",[s._v("progress")]),s._v(" "),a("td",[s._v("文件上传进度,小数 0~1")]),s._v(" "),a("td",[s._v("Number")])]),s._v(" "),a("tr",[a("td",[s._v("file")]),s._v(" "),a("td",[s._v("原始文件")]),s._v(" "),a("td",[s._v("File")])]),s._v(" "),a("tr",[a("td",[s._v("response")]),s._v(" "),a("td",[s._v("响应内容(自动转 JSON)")]),s._v(" "),a("td",[s._v("Object/Array/String")])]),s._v(" "),a("tr",[a("td",[s._v("responseHeaders")]),s._v(" "),a("td",[s._v("响应头")]),s._v(" "),a("td",[s._v("String")])])])])},function(){var s=this,t=s.$createElement,a=s._self._c||t;return a("ul",[a("li",[a("p",[s._v("基本用法")]),s._v(" "),a("pre",{pre:!0},[a("code",{attrs:{"v-pre":"",class:"language-html"}},[a("span",{attrs:{class:"hljs-tag"}},[s._v("<"),a("span",{attrs:{class:"hljs-name"}},[s._v("cube-upload")]),s._v("\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("action")]),s._v("="),a("span",{attrs:{class:"hljs-string"}},[s._v('"//jsonplaceholder.typicode.com/photos/"')]),s._v("\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v(":simultaneous-uploads")]),s._v("="),a("span",{attrs:{class:"hljs-string"}},[s._v('"1"')]),s._v("\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("@files-added")]),s._v("="),a("span",{attrs:{class:"hljs-string"}},[s._v('"filesAdded"')]),s._v(" />")]),s._v("\n")])]),s._v(" "),a("pre",{pre:!0},[a("code",{attrs:{"v-pre":"",class:"language-js"}},[a("span",{attrs:{class:"hljs-keyword"}},[s._v("export")]),s._v(" "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("default")]),s._v(" {\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("methods")]),s._v(": {\n filesAdded(files) {\n "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("let")]),s._v(" hasIgnore = "),a("span",{attrs:{class:"hljs-literal"}},[s._v("false")]),s._v("\n "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("const")]),s._v(" maxSize = "),a("span",{attrs:{class:"hljs-number"}},[s._v("1")]),s._v(" * "),a("span",{attrs:{class:"hljs-number"}},[s._v("1024")]),s._v(" * "),a("span",{attrs:{class:"hljs-number"}},[s._v("1024")]),s._v(" "),a("span",{attrs:{class:"hljs-comment"}},[s._v("// 1M")]),s._v("\n "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("for")]),s._v(" ("),a("span",{attrs:{class:"hljs-keyword"}},[s._v("let")]),s._v(" k "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("in")]),s._v(" files) {\n "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("const")]),s._v(" file = files[k]\n "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("if")]),s._v(" (file.size > maxSize) {\n file.ignore = "),a("span",{attrs:{class:"hljs-literal"}},[s._v("true")]),s._v("\n hasIgnore = "),a("span",{attrs:{class:"hljs-literal"}},[s._v("true")]),s._v("\n }\n }\n hasIgnore && "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("this")]),s._v(".$createToast({\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("type")]),s._v(": "),a("span",{attrs:{class:"hljs-string"}},[s._v("'warn'")]),s._v(",\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("time")]),s._v(": "),a("span",{attrs:{class:"hljs-number"}},[s._v("1000")]),s._v(",\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("txt")]),s._v(": "),a("span",{attrs:{class:"hljs-string"}},[s._v("'You selected >1M files'")]),s._v("\n }).show()\n }\n }\n}\n")])]),s._v(" "),a("p",[s._v("配置 "),a("code",{pre:!0},[s._v("action")]),s._v(" 表示上传的 URL 地址,而 "),a("code",{pre:!0},[s._v("simultaneous-uploads")]),s._v(" 则表示支持的并发上传个数。")]),s._v(" "),a("p",[s._v("通过 "),a("code",{pre:!0},[s._v("files-added")]),s._v(" 事件可以实现文件过滤,设置 "),a("code",{pre:!0},[s._v("file.ignore = true")]),s._v(" 即可。")])]),s._v(" "),a("li",[a("p",[s._v("压缩图片且通过 Base64 上传")]),s._v(" "),a("pre",{pre:!0},[a("code",{attrs:{"v-pre":"",class:"language-html"}},[a("span",{attrs:{class:"hljs-tag"}},[s._v("<"),a("span",{attrs:{class:"hljs-name"}},[s._v("cube-upload")]),s._v("\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("ref")]),s._v("="),a("span",{attrs:{class:"hljs-string"}},[s._v('"upload"')]),s._v("\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v(":action")]),s._v("="),a("span",{attrs:{class:"hljs-string"}},[s._v('"action"')]),s._v("\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v(":simultaneous-uploads")]),s._v("="),a("span",{attrs:{class:"hljs-string"}},[s._v('"1"')]),s._v("\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v(":process-file")]),s._v("="),a("span",{attrs:{class:"hljs-string"}},[s._v('"processFile"')]),s._v("\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("@file-submitted")]),s._v("="),a("span",{attrs:{class:"hljs-string"}},[s._v('"fileSubmitted"')]),s._v(" />")]),s._v("\n")])]),s._v(" "),a("pre",{pre:!0},[a("code",{attrs:{"v-pre":"",class:"language-js"}},[a("span",{attrs:{class:"hljs-keyword"}},[s._v("import")]),s._v(" compress "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("from")]),s._v(" "),a("span",{attrs:{class:"hljs-string"}},[s._v("'../../modules/image'")]),s._v("\n"),a("span",{attrs:{class:"hljs-keyword"}},[s._v("export")]),s._v(" "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("default")]),s._v(" {\n data() {\n "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("return")]),s._v(" {\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("action")]),s._v(": {\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("target")]),s._v(": "),a("span",{attrs:{class:"hljs-string"}},[s._v("'//jsonplaceholder.typicode.com/photos/'")]),s._v(",\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("prop")]),s._v(": "),a("span",{attrs:{class:"hljs-string"}},[s._v("'base64Value'")]),s._v("\n }\n }\n },\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("methods")]),s._v(": {\n processFile(file, next) {\n compress(file, {\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("compress")]),s._v(": {\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("width")]),s._v(": "),a("span",{attrs:{class:"hljs-number"}},[s._v("1600")]),s._v(",\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("height")]),s._v(": "),a("span",{attrs:{class:"hljs-number"}},[s._v("1600")]),s._v(",\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("quality")]),s._v(": "),a("span",{attrs:{class:"hljs-number"}},[s._v("0.5")]),s._v("\n }\n }, next)\n },\n fileSubmitted(file) {\n file.base64Value = file.file.base64\n }\n }\n}\n")])]),s._v(" "),a("p",[a("code",{pre:!0},[s._v("action")]),s._v(" 中除了有 "),a("code",{pre:!0},[s._v("target")]),s._v(" 目标上传地址外;还有 "),a("code",{pre:!0},[s._v("prop")]),s._v(" 配置,表示上传的时候采用处理后的 "),a("code",{pre:!0},[s._v("file")]),s._v(" 普通对象的哪个属性所对应的值上传,这里设置的就是 "),a("code",{pre:!0},[s._v("base64Value")]),s._v(" 的值。")]),s._v(" "),a("p",[a("code",{pre:!0},[s._v("process-file")]),s._v(" 则是一个函数,主要用于处理原生文件的,调用 "),a("code",{pre:!0},[s._v("next")]),s._v(" 回调的话,参数是处理完的文件对象,这里示例的就是调用 "),a("code",{pre:!0},[s._v("compress")]),s._v(" 做压缩,处理完后会回调 "),a("code",{pre:!0},[s._v("next")]),s._v("。")]),s._v(" "),a("p",[a("code",{pre:!0},[s._v("file-submitted")]),s._v(" 事件则是每个文件处理完后添加到 "),a("code",{pre:!0},[s._v("upload")]),s._v(" 实例的 "),a("code",{pre:!0},[s._v("files")]),s._v(" 数组中后触发,参数就是一个处理后的文件对象。")])]),s._v(" "),a("li",[a("p",[s._v("自定义结构样式")]),s._v(" "),a("p",[s._v("使用默认插槽来实现自定义结构,在此基础上自定义样式。")]),s._v(" "),a("pre",{pre:!0},[a("code",{attrs:{"v-pre":"",class:"language-html"}},[a("span",{attrs:{class:"hljs-tag"}},[s._v("<"),a("span",{attrs:{class:"hljs-name"}},[s._v("cube-upload")]),s._v("\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("ref")]),s._v("="),a("span",{attrs:{class:"hljs-string"}},[s._v('"upload"')]),s._v("\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("v-model")]),s._v("="),a("span",{attrs:{class:"hljs-string"}},[s._v('"files"')]),s._v("\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v(":action")]),s._v("="),a("span",{attrs:{class:"hljs-string"}},[s._v('"action"')]),s._v("\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("@files-added")]),s._v("="),a("span",{attrs:{class:"hljs-string"}},[s._v('"addedHandler"')]),s._v("\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("@file-error")]),s._v("="),a("span",{attrs:{class:"hljs-string"}},[s._v('"errHandler"')]),s._v(">")]),s._v("\n "),a("span",{attrs:{class:"hljs-tag"}},[s._v("<"),a("span",{attrs:{class:"hljs-name"}},[s._v("div")]),s._v(" "),a("span",{attrs:{class:"hljs-attr"}},[s._v("class")]),s._v("="),a("span",{attrs:{class:"hljs-string"}},[s._v('"clear-fix"')]),s._v(">")]),s._v("\n "),a("span",{attrs:{class:"hljs-tag"}},[s._v("<"),a("span",{attrs:{class:"hljs-name"}},[s._v("cube-upload-file")]),s._v(" "),a("span",{attrs:{class:"hljs-attr"}},[s._v("v-for")]),s._v("="),a("span",{attrs:{class:"hljs-string"}},[s._v('"(file, i) in files"')]),s._v(" "),a("span",{attrs:{class:"hljs-attr"}},[s._v(":file")]),s._v("="),a("span",{attrs:{class:"hljs-string"}},[s._v('"file"')]),s._v(" "),a("span",{attrs:{class:"hljs-attr"}},[s._v(":key")]),s._v("="),a("span",{attrs:{class:"hljs-string"}},[s._v('"i"')]),s._v(">")]),a("span",{attrs:{class:"hljs-tag"}},[s._v("</"),a("span",{attrs:{class:"hljs-name"}},[s._v("cube-upload-file")]),s._v(">")]),s._v("\n "),a("span",{attrs:{class:"hljs-tag"}},[s._v("<"),a("span",{attrs:{class:"hljs-name"}},[s._v("cube-upload-btn")]),s._v(" "),a("span",{attrs:{class:"hljs-attr"}},[s._v(":multiple")]),s._v("="),a("span",{attrs:{class:"hljs-string"}},[s._v('"false"')]),s._v(">")]),s._v("\n "),a("span",{attrs:{class:"hljs-tag"}},[s._v("<"),a("span",{attrs:{class:"hljs-name"}},[s._v("div")]),s._v(">")]),s._v("\n "),a("span",{attrs:{class:"hljs-tag"}},[s._v("<"),a("span",{attrs:{class:"hljs-name"}},[s._v("i")]),s._v(">")]),s._v("+"),a("span",{attrs:{class:"hljs-tag"}},[s._v("</"),a("span",{attrs:{class:"hljs-name"}},[s._v("i")]),s._v(">")]),s._v("\n "),a("span",{attrs:{class:"hljs-tag"}},[s._v("<"),a("span",{attrs:{class:"hljs-name"}},[s._v("p")]),s._v(">")]),s._v("Please click to upload ID card"),a("span",{attrs:{class:"hljs-tag"}},[s._v("</"),a("span",{attrs:{class:"hljs-name"}},[s._v("p")]),s._v(">")]),s._v("\n "),a("span",{attrs:{class:"hljs-tag"}},[s._v("</"),a("span",{attrs:{class:"hljs-name"}},[s._v("div")]),s._v(">")]),s._v("\n "),a("span",{attrs:{class:"hljs-tag"}},[s._v("</"),a("span",{attrs:{class:"hljs-name"}},[s._v("cube-upload-btn")]),s._v(">")]),s._v("\n "),a("span",{attrs:{class:"hljs-tag"}},[s._v("</"),a("span",{attrs:{class:"hljs-name"}},[s._v("div")]),s._v(">")]),s._v("\n"),a("span",{attrs:{class:"hljs-tag"}},[s._v("</"),a("span",{attrs:{class:"hljs-name"}},[s._v("cube-upload")]),s._v(">")]),s._v("\n")])]),s._v(" "),a("pre",{pre:!0},[a("code",{attrs:{"v-pre":"",class:"language-js"}},[a("span",{attrs:{class:"hljs-keyword"}},[s._v("export")]),s._v(" "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("default")]),s._v(" {\n data() {\n "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("return")]),s._v(" {\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("action")]),s._v(": "),a("span",{attrs:{class:"hljs-string"}},[s._v("'//jsonplaceholder.typicode.com/photos/'")]),s._v(",\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("files")]),s._v(": []\n }\n },\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("methods")]),s._v(": {\n addedHandler() {\n "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("const")]),s._v(" file = "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("this")]),s._v(".files["),a("span",{attrs:{class:"hljs-number"}},[s._v("0")]),s._v("]\n file && "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("this")]),s._v(".$refs.upload.removeFile(file)\n },\n errHandler(file) {\n "),a("span",{attrs:{class:"hljs-comment"}},[s._v("// const msg = file.response.message")]),s._v("\n "),a("span",{attrs:{class:"hljs-keyword"}},[s._v("this")]),s._v(".$createToast({\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("type")]),s._v(": "),a("span",{attrs:{class:"hljs-string"}},[s._v("'warn'")]),s._v(",\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("txt")]),s._v(": "),a("span",{attrs:{class:"hljs-string"}},[s._v("'Upload fail'")]),s._v(",\n "),a("span",{attrs:{class:"hljs-attr"}},[s._v("time")]),s._v(": "),a("span",{attrs:{class:"hljs-number"}},[s._v("1000")]),s._v("\n }).show()\n }\n }\n}\n")])]),s._v(" "),a("p",[s._v("样式覆盖:")]),s._v(" "),a("pre",{pre:!0},[a("code",{attrs:{"v-pre":"",class:"language-stylus"}},[a("span",{attrs:{class:"hljs-selector-class"}},[s._v(".cube-upload")]),s._v("\n "),a("span",{attrs:{class:"hljs-selector-class"}},[s._v(".cube-upload-file")]),s._v(", "),a("span",{attrs:{class:"hljs-selector-class"}},[s._v(".cube-upload-btn")]),s._v("\n "),a("span",{attrs:{class:"hljs-attribute"}},[s._v("margin")]),s._v(": "),a("span",{attrs:{class:"hljs-number"}},[s._v("0")]),s._v("\n "),a("span",{attrs:{class:"hljs-attribute"}},[s._v("height")]),s._v(": "),a("span",{attrs:{class:"hljs-number"}},[s._v("200px")]),s._v("\n "),a("span",{attrs:{class:"hljs-selector-class"}},[s._v(".cube-upload-file")]),s._v("\n "),a("span",{attrs:{class:"hljs-attribute"}},[s._v("margin")]),s._v(": "),a("span",{attrs:{class:"hljs-number"}},[s._v("0")]),s._v("\n + "),a("span",{attrs:{class:"hljs-selector-class"}},[s._v(".cube-upload-btn")]),s._v("\n "),a("span",{attrs:{class:"hljs-attribute"}},[s._v("margin-top")]),s._v(": -"),a("span",{attrs:{class:"hljs-number"}},[s._v("200px")]),s._v("\n "),a("span",{attrs:{class:"hljs-attribute"}},[s._v("opacity")]),s._v(": "),a("span",{attrs:{class:"hljs-number"}},[s._v("0")]),s._v("\n "),a("span",{attrs:{class:"hljs-selector-class"}},[s._v(".cube-upload-file-def")]),s._v("\n "),a("span",{attrs:{class:"hljs-attribute"}},[s._v("width")]),s._v(": "),a("span",{attrs:{class:"hljs-number"}},[s._v("100%")]),s._v("\n "),a("span",{attrs:{class:"hljs-attribute"}},[s._v("height")]),s._v(": "),a("span",{attrs:{class:"hljs-number"}},[s._v("100%")]),s._v("\n "),a("span",{attrs:{class:"hljs-selector-class"}},[s._v(".cubeic-wrong")]),s._v("\n "),a("span",{attrs:{class:"hljs-attribute"}},[s._v("display")]),s._v(": none\n "),a("span",{attrs:{class:"hljs-selector-class"}},[s._v(".cube-upload-btn")]),s._v("\n "),a("span",{attrs:{class:"hljs-attribute"}},[s._v("display")]),s._v(": flex\n "),a("span",{attrs:{class:"hljs-attribute"}},[s._v("align-items")]),s._v(": center\n "),a("span",{attrs:{class:"hljs-attribute"}},[s._v("justify-content")]),s._v(": center\n > "),a("span",{attrs:{class:"hljs-selector-tag"}},[s._v("div")]),s._v("\n "),a("span",{attrs:{class:"hljs-attribute"}},[s._v("text-align")]),s._v(": center\n "),a("span",{attrs:{class:"hljs-selector-tag"}},[s._v("i")]),s._v("\n "),a("span",{attrs:{class:"hljs-attribute"}},[s._v("display")]),s._v(": inline-flex\n "),a("span",{attrs:{class:"hljs-attribute"}},[s._v("align-items")]),s._v(": center\n "),a("span",{attrs:{class:"hljs-attribute"}},[s._v("justify-content")]),s._v(": center\n "),a("span",{attrs:{class:"hljs-attribute"}},[s._v("width")]),s._v(": "),a("span",{attrs:{class:"hljs-number"}},[s._v("50px")]),s._v("\n "),a("span",{attrs:{class:"hljs-attribute"}},[s._v("height")]),s._v(": "),a("span",{attrs:{class:"hljs-number"}},[s._v("50px")]),s._v("\n "),a("span",{attrs:{class:"hljs-attribute"}},[s._v("margin-bottom")]),s._v(": "),a("span",{attrs:{class:"hljs-number"}},[s._v("20px")]),s._v("\n "),a("span",{attrs:{class:"hljs-attribute"}},[s._v("font-size")]),s._v(": "),a("span",{attrs:{class:"hljs-number"}},[s._v("32px")]),s._v("\n "),a("span",{attrs:{class:"hljs-attribute"}},[s._v("line-height")]),s._v(": "),a("span",{attrs:{class:"hljs-number"}},[s._v("1")]),s._v("\n "),a("span",{attrs:{class:"hljs-attribute"}},[s._v("font-style")]),s._v(": normal\n "),a("span",{attrs:{class:"hljs-attribute"}},[s._v("color")]),s._v(": "),a("span",{attrs:{class:"hljs-number"}},[s._v("#fff")]),s._v("\n "),a("span",{attrs:{class:"hljs-attribute"}},[s._v("background-color")]),s._v(": "),a("span",{attrs:{class:"hljs-number"}},[s._v("#333")]),s._v("\n "),a("span",{attrs:{class:"hljs-attribute"}},[s._v("border-radius")]),s._v(": "),a("span",{attrs:{class:"hljs-number"}},[s._v("50%")]),s._v("\n")])]),s._v(" "),a("p",[s._v("上述示例实现的效果就是点击上传(一次只能选择一张)一张图片,此图片就会直接展示,而上传按钮本身则是不可见,覆盖在图片预览区域上。再次重新选择图片,就会移除掉上次选择的图片,重新展示新选择的图片。")])])])},function(){var s=this,t=s.$createElement,a=s._self._c||t;return a("table",[a("thead",[a("tr",[a("th",[s._v("参数")]),s._v(" "),a("th",[s._v("说明")]),s._v(" "),a("th",[s._v("类型")]),s._v(" "),a("th",[s._v("默认值")]),s._v(" "),a("th",[s._v("示例")])])]),s._v(" "),a("tbody",[a("tr",[a("td",[s._v("action")]),s._v(" "),a("td",[s._v("上传行为配置项,最少包含上传目标的 URL 地址")]),s._v(" "),a("td",[s._v("String/Object")]),s._v(" "),a("td",[s._v("''")]),s._v(" "),a("td",[s._v("{ target: '/upload' }")])]),s._v(" "),a("tr",[a("td",[s._v("max")]),s._v(" "),a("td",[s._v("最大上传文件个数")]),s._v(" "),a("td",[s._v("Number")]),s._v(" "),a("td",[s._v("10")]),s._v(" "),a("td",[s._v("-")])]),s._v(" "),a("tr",[a("td",[s._v("auto")]),s._v(" "),a("td",[s._v("是否自动上传,即选择完文件后自动开始上传")]),s._v(" "),a("td",[s._v("Boolean")]),s._v(" "),a("td",[s._v("true")]),s._v(" "),a("td",[s._v("-")])]),s._v(" "),a("tr",[a("td",[s._v("simultaneousUploads")]),s._v(" "),a("td",[s._v("并发上传数")]),s._v(" "),a("td",[s._v("Number")]),s._v(" "),a("td",[s._v("1")]),s._v(" "),a("td",[s._v("-")])]),s._v(" "),a("tr",[a("td",[s._v("processFile")]),s._v(" "),a("td",[s._v("处理原始文件函数")]),s._v(" "),a("td",[s._v("Function")]),s._v(" "),a("td",[s._v("function (file, next) { next(file) }")]),s._v(" "),a("td",[s._v("-")])])])])},function(){var s=this,t=s.$createElement,a=s._self._c||t;return a("ul",[a("li",[a("code",{pre:!0},[s._v("action")]),s._v(" 子配置项")])])},function(){var s=this,t=s.$createElement,a=s._self._c||t;return a("p",[s._v("如果 "),a("code",{pre:!0},[s._v("action")]),s._v(" 是字符串,则会被处理成 "),a("code",{pre:!0},[s._v("{ target: action }")]),s._v(" 这样结构。")])},function(){var s=this,t=s.$createElement,a=s._self._c||t;return a("table",[a("thead",[a("tr",[a("th",[s._v("参数")]),s._v(" "),a("th",[s._v("说明")]),s._v(" "),a("th",[s._v("类型")]),s._v(" "),a("th",[s._v("默认值")])])]),s._v(" "),a("tbody",[a("tr",[a("td",[s._v("target")]),s._v(" "),a("td",[s._v("上传目标 URL")]),s._v(" "),a("td",[s._v("String")]),s._v(" "),a("td",[s._v("-")])]),s._v(" "),a("tr",[a("td",[s._v("fileName")]),s._v(" "),a("td",[s._v("上传文件时文件的参数名")]),s._v(" "),a("td",[s._v("String")]),s._v(" "),a("td",[s._v("'file'")])]),s._v(" "),a("tr",[a("td",[s._v("prop")]),s._v(" "),a("td",[s._v("上传的时候使用文件对象的 prop 属性所对应的值")]),s._v(" "),a("td",[s._v("String")]),s._v(" "),a("td",[s._v("'file'")])]),s._v(" "),a("tr",[a("td",[s._v("headers")]),s._v(" "),a("td",[s._v("自定义请求头")]),s._v(" "),a("td",[s._v("Object")]),s._v(" "),a("td",[s._v("{}")])]),s._v(" "),a("tr",[a("td",[s._v("data")]),s._v(" "),a("td",[s._v("上传需要附加数据")]),s._v(" "),a("td",[s._v("Object")]),s._v(" "),a("td",[s._v("{}")])]),s._v(" "),a("tr",[a("td",[s._v("withCredentials")]),s._v(" "),a("td",[s._v("标准的 CORS 请求是不会带上 cookie 的,如果想要带的话需要设置 withCredentials 为 true")]),s._v(" "),a("td",[s._v("Boolean")]),s._v(" "),a("td",[s._v("false")])]),s._v(" "),a("tr",[a("td",[s._v("timeout")]),s._v(" "),a("td",[s._v("请求超时时间")]),s._v(" "),a("td",[s._v("Number")]),s._v(" "),a("td",[s._v("0")])]),s._v(" "),a("tr",[a("td",[s._v("progressInterval")]),s._v(" "),a("td",[s._v("进度回调间隔(单位:ms)")]),s._v(" "),a("td",[s._v("Number")]),s._v(" "),a("td",[s._v("100")])]),s._v(" "),a("tr",[a("td",[s._v("checkSuccess")]),s._v(" "),a("td",[s._v("校验是否成功函数,参数为服务端响应数据,返回值为 true 则代表成功")]),s._v(" "),a("td",[s._v("Function")]),s._v(" "),a("td",[s._v("function (res) { return true }")])])])])},function(){var s=this,t=s.$createElement,a=s._self._c||t;return a("ul",[a("li",[a("code",{pre:!0},[s._v("processFile")]),s._v(" 子配置项")])])},function(){var s=this,t=s.$createElement,a=s._self._c||t;return a("p",[s._v("一个函数,这个函数有两个参数:"),a("code",{pre:!0},[s._v("(file, next)")]),s._v(","),a("code",{pre:!0},[s._v("file")]),s._v(" 就是原始文件,"),a("code",{pre:!0},[s._v("next")]),s._v(" 为处理完毕后的回调函数,调用的时候需要传入处理后的文件。")])},function(){var s=this,t=s.$createElement,a=s._self._c||t;return a("table",[a("thead",[a("tr",[a("th",[s._v("事件名")]),s._v(" "),a("th",[s._v("说明")]),s._v(" "),a("th",[s._v("参数")])])]),s._v(" "),a("tbody",[a("tr",[a("td",[s._v("files-added")]),s._v(" "),a("td",[s._v("选择完文件后触发,一般可用作文件过滤")]),s._v(" "),a("td",[s._v("原始文件列表")])]),s._v(" "),a("tr",[a("td",[s._v("file-submitted")]),s._v(" "),a("td",[s._v("每个文件处理完后添加到 "),a("code",{pre:!0},[s._v("upload")]),s._v(" 实例的 "),a("code",{pre:!0},[s._v("files")]),s._v(" 数组中后触发")]),s._v(" "),a("td",[s._v("文件对象")])]),s._v(" "),a("tr",[a("td",[s._v("file-removed")]),s._v(" "),a("td",[s._v("文件被删除后触发")]),s._v(" "),a("td",[s._v("文件对象")])]),s._v(" "),a("tr",[a("td",[s._v("file-success")]),s._v(" "),a("td",[s._v("文件上传成功后触发")]),s._v(" "),a("td",[s._v("文件对象")])]),s._v(" "),a("tr",[a("td",[s._v("file-error")]),s._v(" "),a("td",[s._v("文件上传失败后触发")]),s._v(" "),a("td",[s._v("文件对象")])]),s._v(" "),a("tr",[a("td",[s._v("file-click")]),s._v(" "),a("td",[s._v("文件点击后触发")]),s._v(" "),a("td",[s._v("文件对象")])])])])},function(){var s=this,t=s.$createElement,a=s._self._c||t;return a("table",[a("thead",[a("tr",[a("th",[s._v("方法名")]),s._v(" "),a("th",[s._v("说明")]),s._v(" "),a("th",[s._v("参数")])])]),s._v(" "),a("tbody",[a("tr",[a("td",[s._v("start")]),s._v(" "),a("td",[s._v("开始上传")]),s._v(" "),a("td",[s._v("-")])]),s._v(" "),a("tr",[a("td",[s._v("pause")]),s._v(" "),a("td",[s._v("暂停上传")]),s._v(" "),a("td",[s._v("-")])]),s._v(" "),a("tr",[a("td",[s._v("retry")]),s._v(" "),a("td",[s._v("重试上传")]),s._v(" "),a("td",[s._v("-")])]),s._v(" "),a("tr",[a("td",[s._v("removeFile")]),s._v(" "),a("td",[s._v("删除文件")]),s._v(" "),a("td",[s._v("文件对象")])])])])}]}}});