当我的 Vue 应用无法在 IE11 上呈现时,如何显示免责声明屏幕?



我的应用程序是在Vue中开发的,目前它在IE11和旧边缘中工作不太好,我可以渲染一个"请更新您的浏览器屏幕";边缘,因为应用程序会加载一些,然而IE11只是显示了一个空白屏幕。

我如何检查用户是否在IE11上,然后只呈现一个普通的HTML/CSS页面,要求他们更新浏览器?

我以前遇到过这种问题。我检测到浏览器版本,如果IE,然后呈现一些你需要的消息。如果不是IE,则渲染vue应用程序。

我在public/index.html中使用JavaScript来检测浏览器,代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title>my-vue-app</title>
</head>
<body>
<noscript>
<strong>We're sorry but my-vue-app doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<!-- built files will be auto injected -->
<script type="text/javascript">
function get_browser() {
var ua = navigator.userAgent, tem, M = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=/))/?s*(d+)/i) || [];
if (/trident/i.test(M[1])) {
tem = /brv[ :]+(d+)/g.exec(ua) || [];
return { name: 'IE', version: (tem[1] || '') };
}
if (M[1] === 'Chrome') {
tem = ua.match(/bOPR/(d+)/)
if (tem != null) { return { name: 'Opera', version: tem[1] }; }
}
if (window.navigator.userAgent.indexOf("Edge") > -1) {
tem = ua.match(/Edge/(d+)/)
if (tem != null) { return { name: 'Edge', version: tem[1] }; }      
}
M = M[2] ? [M[1], M[2]] : [navigator.appName, navigator.appVersion, '-?'];
if ((tem = ua.match(/version/(d+)/i)) != null) { M.splice(1, 1, tem[1]); }
return {
name: M[0],
version: +M[1]
};
}
var browser = get_browser()
var isSupported = isSupported(browser);
function isSupported(browser) {
var supported = false;
if (browser.name === "Chrome" && browser.version >= 48) {
supported = true;
} else if ((browser.name === "MSIE" || browser.name === "IE") && browser.version <= 11) {
supported = false;
} else if (browser.name === "Edge") {
supported = true;
}
return supported;
}
if (!isSupported) {
//render unsupported message
document.write("<h1>The app is not supported in IE. Please use other browsers!</h1>");
}
else{
//render app
var elem = document.createElement("div");
elem.setAttribute("id", "app")
document.body.appendChild(elem);
}
</script>
</body>
</html>

你不需要,你尝试过吗:https://cli.vuejs.org/guide/browser-compatibility.html#browserslist?

最新更新