关于electron的跨域问题,有本地的图片的地址,访问不了本地的图片
2017-06-29 09:56
1436 查看
项目中有上传图片功能,自定义input type=file 改变透明度和超出部分隐藏,把按钮和
点击的图标放在上传文件的按钮上面,然后又碰到到获取input里面的图片的本地的路径,
在electron就是不能跨域访问本地,如何解决呢:
百事不得其解,问了我们项目的老大,说是electron的跨域问题,改变如下
点击的图标放在上传文件的按钮上面,然后又碰到到获取input里面的图片的本地的路径,
在electron就是不能跨域访问本地,如何解决呢:
百事不得其解,问了我们项目的老大,说是electron的跨域问题,改变如下
webSecurity webPreferences:{nodeIntegration: false, preload: js文件绝对路径 }
//发送图片 sendImgFile(){ console.log("this is sendImgFile click") var files = this.$refs.inputImg.files; //获取input里面的图片的地址后者文件的本地路径; var size = files[0].size;//大小 var file_path = files[0].path;//文件的本地路径 this.file_paths = file_path console.log("获取图片的files:",files,"获取图片的大小:",size,"获取图片本地的地址:",file_path); var content = '<img src= "' + file_path + '" class="file-img">'; 拼接img标签 // var content = '<img :src="'+this.file_paths+'">' this.$refs.chatSendContainer.innerHTML = content; },
import { BrowserWindow, globalShortcut, Menu } from 'electron' import Common from '../common/common.js' const winURL = process.env.NODE_ENV === 'development' ? `http://localhost:${require('../../../../config').port}` : `file://${__dirname}/index.html` function createWindow() { var mainWindow = new BrowserWindow({ height: Common.WINDOW_SIZE_LOGIN.height, width: Common.WINDOW_SIZE_LOGIN.width, resizable: false, frame: false, webPreferences:{webSecurity: false}//加上这个就可以获取到了本地的图片 }); mainWindow.loadURL(winURL); mainWindow.on('closed', () => { mainWindow = null }); //前期为了调试方面,默认打开控制台 mainWindow.webContents.openDevTools({ detach: true }); //注册打开控制台的快捷键 globalShortcut.register('ctrl+shift+alt+e', function () { let win = BrowserWindow.getFocusedWindow(); if (win) { win.webContents.openDevTools({ detach: true }); } }); //去掉默认菜单栏 Menu.setApplicationMenu(null); // eslint-disable-next-line no-console console.log('mainWindow opened'); BrowserWindow.mainWindow = mainWindow; return mainWindow; } module.exports = { createWindow };
相关文章推荐
- Silverlight关于跨域访问问题?
- 关于使用Silverlight通过IP地址访问本地ArcGIS Server发布的Rest服务无法出图的问题
- 关于ImageLoader加载本地缓存下来的图片的问题?
- 关于SqlServer 2008本地无法登陆或访问本地服务器的问题
- 关于在做java的Web开发中遇到跨域访问的问题的解决方法汇总
- java下载远程http地址的图片文件到本地-自动处理图片是否经过服务器gzip压缩的问题
- java下载远程http地址的图片文件到本地-自动处理图片是否经过服务器gzip压缩的问题
- 黄聪:python访问抓取网页常用命令(保存图片到本地、模拟POST、GET、中文编码问题)
- jquery ajax 访问本地地址问题
- 关于Android模拟器访问本地地址
- 关于解决Flex跨域访问的沙箱冲突问题
- 关于tomcat启动后,直接访问本地地址默认的页面
- 关于Applet利用数字签名获得本地访问权限的问题
- 关于ArcGIS FlexViewer访问地图服务跨域问题
- flex安全沙箱,跨域访问图片资源问题解决
- Windows Authentication 关于本地开发不同域名访问的问题
- android红米等关于读取本地文件夹图片获取路径的问题的解决
- 关于Silverlight的跨域访问问题
- asp.net 开发过程中关于image控件中图片点击后地址乱码的问题