1.新建文件common.js,如下:

   


export default{ 

   changeImage:function(){
        let imgHeight = window.document.querySelector("#code").offsetHeight; // 获取DOM高度
    },

   //将图片Base64 转成文件
    dataURLtoFile:function(dataurl, filename) {
        console.log("转文件")
        var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
            bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
        while(n--){
            u8arr[n] = bstr.charCodeAt(n);
        }
        return new File([u8arr], filename, {type:mime});
    }
 }

2.在main.js引入并且挂载 

import common from './assets/common.js';
Vue.prototype.common = common

3.在vue文件中调用

 

this.common.changeImage();

 

 

Logo

前往低代码交流专区

更多推荐