【解决IE9打开页面白屏的问题】
刚刚解决了IE11白屏的问题,现在又换用另一台装了Vista SP2系统的电脑,用IE9打开这个Vue2网站,会发现仍然白屏,除非按F12打开Web调试工具再刷新页面。
这是因为IE9没打开F12调试模式(IE Dev Tools)的时候,是不支持console打印日志的,console对象为undefined导致脚本错误。
解决办法是,在my-project/public目录下新建一个remove_console.js文件,内容为
// IE9里console的处理
(function () {
var method
var noop = function () {}
var methods = [
'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',
'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log',
'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',
'timeline', 'timelineEnd', 'timeStamp', 'trace', 'warn'
]
var length = (methods.length)
var console = (window.console=window.console|| {})
while (length--) {
method = methods[length]
if (!console[method]) {
console[method] = noop
}
}
}())
再修改已有的my-project/public/index.html文件,在</title>下方加入
<script src="<%= BASE_URL %>remove_console.js"></script>
保存文件后,不用重启http服务器就可以立即生效,IE9可以正常显示Vue2页面了!