Export the XLS file

ExportXls (data,name){console.log(data,'data is a file stream ') if(! Data){Message({type: 'error', Message: 'error'}) return false} const blob = new blob ([data], {type: 'application/vnd.ms-excel' }) const link = document.createElement('a') link.href = window.URL.createObjectURL(blob) const date = +new Date() link.download = name + date + '.xls' link.click() }Copy the code

Download the image locally

import download from 'downloadjs' const utils = { getBase64Image(img, width, height) { var canvas = document.createElement('canvas') canvas.width = width || img.width canvas.height = height || img.height var ctx = canvas.getContext('2d') ctx.drawImage(img, 0, 0, canvas.width, canvas.height) var dataURL = canvas.toDataURL() return dataURL }, getCanvasBase64(img, callback, width, height) { var self = this var image = new Image() image.crossOrigin = '' image.src = img if (img) { image.onload = function() { callback(self.getBase64Image(image, width, height)) } } }, downloadQRBase64(base64, name = 'QR') { download(base64, `${name}.png`, 'image/png') }, downloadQR(url, width = 50, height = 50, name = `qrcode-${width}x${height}`) { if (url.indexOf('? ') === -1) { url += '? t=' + (+new Date()) } this.getCanvasBase64(url, function(base64) { download(base64, `${name}.png`, 'image/png') }, Width, height)}, / * * / getUrlParam interception parameters (name, url = ' ') {var reg = new RegExp (" (^ | &) "+ name +" = (/ ^ & *) (& | $) "); let index = url.indexOf('? ') url = url.substr(index == -1 ? 0 : index + 1); var r = url.match(reg) if (r ! = null) return unescape(r[2]) return null}} Call method downloadQR(url + '? t=' + (+new Date()), 300, 300, `qrcode_${date}`)Copy the code

replication

Vue-clipboard2 use cases are as follows: <el-button V-clipboard :copy="scope.row.qrcode" v-clipboard:success="onCopysuccess" V-clipboard :error="onCopyerror"> Copy </el-button>Copy the code

API engineering management

1. The simple version is in a single folder

const apiContent = require.context(('./api/', true, /\.js$/)) const api = {} Object.keys(apiContent).forEach((key) => { const apiName = key.split('/').pop().replace(/\.\w+$/, ") API [apiName] = apiContent(key)}) export default {install(Vue) {vue.prototype.$API = API}}  import apiUtils from '@/apiUtils' Vue.use(apiUtils)Copy the code