| | |
| | | <template> |
| | | <div class="imgBox"> |
| | | <img :src="'/httpImage/' + url" class="cursor-pointer" v-if="isPreview" preview /> |
| | | <img :src="'/httpImage/' + url" v-if="!isPreview" /> |
| | | <el-button class="btn" @click="downloadIamge('/httpImage/' + url)"> |
| | | <img |
| | | :src="'http://' + url" |
| | | class="cursor-pointer" |
| | | v-if="isPreview" |
| | | preview |
| | | /> |
| | | <img :src="'http://' + url" v-if="!isPreview" /> |
| | | <el-button class="btn" @click="downloadIamge('http://' + url)"> |
| | | <i class="iconfont iconxiazai"></i> |
| | | </el-button> |
| | | </div> |
| | | </template> |
| | | <script> |
| | | import axios from "axios" |
| | | import axios from "axios"; |
| | | export default { |
| | | props: { |
| | | url: { |
| | | default: "", |
| | | type: String |
| | | type: String, |
| | | }, |
| | | isPreview: { |
| | | default: true, |
| | | type: Boolean |
| | | } |
| | | type: Boolean, |
| | | }, |
| | | }, |
| | | methods: { |
| | | downloadIamge(url) { |
| | | axios({ |
| | | method: "get", |
| | | url: url, |
| | | responseType: "blob" |
| | | responseType: "blob", |
| | | }) |
| | | .then((res) => { |
| | | if (res.status == 200) { |
| | | var a = document.createElement("a") |
| | | var strs = url.split("/") |
| | | var href = new Blob([res.data], { type: "image/jpeg" }) |
| | | a.href = URL.createObjectURL(href) |
| | | a.download = strs[strs.length - 1] + ".jpg" |
| | | a.click() |
| | | var a = document.createElement("a"); |
| | | var strs = url.split("/"); |
| | | var href = new Blob([res.data], { type: "image/jpeg" }); |
| | | a.href = URL.createObjectURL(href); |
| | | a.download = strs[strs.length - 1] + ".jpg"; |
| | | a.click(); |
| | | } |
| | | }) |
| | | .catch((err) => { |
| | | if (err && err.status == 401) { |
| | | return |
| | | return; |
| | | } |
| | | this.$notify({ |
| | | type: "error", |
| | | message: "下载失败," + err + "请重试!", |
| | | duration: 2500, |
| | | offset: 57 |
| | | }) |
| | | }) |
| | | } |
| | | } |
| | | } |
| | | offset: 57, |
| | | }); |
| | | }); |
| | | }, |
| | | }, |
| | | }; |
| | | </script> |
| | | <style lang="scss" scoped> |
| | | .imgBox { |