data () {
return{
browser: ''
}
}
mounted () {
let userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
console.log(userAgent);
let self = this;
let isOpera = userAgent.indexOf("Opera") > -1;
//判断是否Opera浏览器
if (isOpera) {
self.browser = "Opera";
}
//判断是否Firefox浏览器
else if (userAgent.indexOf("Firefox") > -1) {
self.browser = "Firefox";
}
//判断是否Edge浏览器
else if (userAgent.indexOf("Edge") > -1 || userAgent.indexOf("Edg") > -1) {
self.browser = "Edge";
}
//判断是否IE浏览器
else if (userAgent.indexOf("Trident") > -1) {
self.browser = "IE";
}
//判断是否chrome浏览器
else if (userAgent.indexOf("Chrome") > -1){
self.browser = "Chrome";
}
//判断是否Safari浏览器
else if (userAgent.indexOf("Safari") > -1) {
self.browser = "Safari";
}
//判断是否IE浏览器
else if (userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera) {
self.browser = "IE";
}
}