在IE11浏览器中,router-link的跳转是失效的,主要是因为当url的hash变化的时候,浏览器没有做出相应的反应。这时候需要做一个兼容处理,当浏览器是IE11时手动给url加一个hashChange事件。
解决,在vue项目的main.js里面加上这段:
if (
'-ms-scroll-limit' in document.documentElement.style &&
'-ms-ime-align' in document.documentElement.style
) { // detect it's IE11
window.addEventListener("hashchange", function(event) {
var currentPath = window.location.hash.slice(1);
if (store.state.route.path !== currentPath) {
router.push(currentPath)
}
}, false)
}
参考:https://segmentfault.com/q/1010000011782885
https://blog.csdn.net/zyg1515330502/article/details/94724277