如何把上传图片时候的文件对象转换为图片的url !

时间:2019-07-11 16:36:19   收藏:0   阅读:225
 getObjectURL(file) {
      var url = null;
      if (window.createObjectURL != undefined) {
        url = window.createObjectURL(file);
      } else if (window.URL != undefined) {
        url = window.URL.createObjectURL(file);
      } else if (window.webkitURL != undefined) {
        url = window.webkitURL.createObjectURL(file);
      }
      return url;
    },

以上,我们通过将文件对象传入,即可返回图片的url .

若是其他文件内容,我们直接用对象.name  直接展示文件名称即可。

原文:https://www.cnblogs.com/teamemory/p/11170768.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!