电子不使用更新的 css 文件
Electron not using updated css file
我正在使用 electron 制作应用程序。直到现在我才能够加载我的 css 文件(更新版本)。但是我突然发现,如果我在 css 文件中进行任何更改,这些更改将不再反映在 electron 中。类似的事情发生在 wjen 我曾经在 Chrome 浏览器中 运行 同样的事情但是我通过清除缓存让它工作。
我认为清除电子缓存也可能对我有帮助,但我不知道该怎么做。
我从某处得到这段代码,但我不知道如何使用它:(
var remote = require('remote');
var win = remote.getCurrentWindow();
win.webContents.session.clearCache(function(){
//some callback.
}
谁能指导我如何解决我的问题。
更新:
const electron = require('electron');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
var mainWindow = null;
app.on('window-all-closed', function() {
app.quit();
});
app.on('ready', function() {
var subpy = require('child_process').spawn('python', ['./index.py']);
var rq = require('request-promise');
var mainAddr = 'http://localhost:5000';
var openWindow = function(){
mainWindow = new BrowserWindow({width:1200, height: 700});
mainWindow.loadURL('http://localhost:5000');
mainWindow.webContents.openDevTools();
mainWindow.on('closed', function() {
mainWindow = null;
subpy.kill('SIGINT');
});
};
var startUp = function(){
rq(mainAddr)
.then(function(htmlString){
console.log('server started!');
openWindow();
})
.catch(function(err){
startUp();
});
};
startUp();
});
来自文档站点:
const {BrowserWindow} = require('electron');
let win = new BrowserWindow({width: 800, height: 600});
win.loadURL('http://github.com');
const ses = win.webContents.session.clearCache(function() {
});
因此,以下函数将 return 您拥有的 window 并将其保存在 win 变量中。
var remote = require('remote');
var win = remote.getCurrentWindow();
然后,使用您在文档站点上使用的相同功能:
win.webContents.session.clearCache(function(){
// some callback.
});
您将从当前 window 中清除缓存。如果您之前已将 windows 的值存储在某个变量上,则无需使用 getCurrentWindow()
函数获取它。
我正在使用 electron 制作应用程序。直到现在我才能够加载我的 css 文件(更新版本)。但是我突然发现,如果我在 css 文件中进行任何更改,这些更改将不再反映在 electron 中。类似的事情发生在 wjen 我曾经在 Chrome 浏览器中 运行 同样的事情但是我通过清除缓存让它工作。 我认为清除电子缓存也可能对我有帮助,但我不知道该怎么做。 我从某处得到这段代码,但我不知道如何使用它:(
var remote = require('remote');
var win = remote.getCurrentWindow();
win.webContents.session.clearCache(function(){
//some callback.
}
谁能指导我如何解决我的问题。
更新:
const electron = require('electron');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
var mainWindow = null;
app.on('window-all-closed', function() {
app.quit();
});
app.on('ready', function() {
var subpy = require('child_process').spawn('python', ['./index.py']);
var rq = require('request-promise');
var mainAddr = 'http://localhost:5000';
var openWindow = function(){
mainWindow = new BrowserWindow({width:1200, height: 700});
mainWindow.loadURL('http://localhost:5000');
mainWindow.webContents.openDevTools();
mainWindow.on('closed', function() {
mainWindow = null;
subpy.kill('SIGINT');
});
};
var startUp = function(){
rq(mainAddr)
.then(function(htmlString){
console.log('server started!');
openWindow();
})
.catch(function(err){
startUp();
});
};
startUp();
});
来自文档站点:
const {BrowserWindow} = require('electron');
let win = new BrowserWindow({width: 800, height: 600});
win.loadURL('http://github.com');
const ses = win.webContents.session.clearCache(function() {
});
因此,以下函数将 return 您拥有的 window 并将其保存在 win 变量中。
var remote = require('remote');
var win = remote.getCurrentWindow();
然后,使用您在文档站点上使用的相同功能:
win.webContents.session.clearCache(function(){
// some callback.
});
您将从当前 window 中清除缓存。如果您之前已将 windows 的值存储在某个变量上,则无需使用 getCurrentWindow()
函数获取它。