vue項目router-link在IE下不跳轉,失效

在IE11瀏覽器中,router-link的跳轉是失效的,主要是因爲當url的hash變化的時候,瀏覽器沒有做出相應的反應。這時候需要做一個兼容處理,當瀏覽器是IE11時手動給url加一個hashChange事件。

辦法一:

new Vue({
	el: '#app',
	router,
	components: {
		App
	},
	template: '<App/>',
	render: function(createElement) {
		if ('-ms-scroll-limit' in document.documentElement.style && '-ms-ime-align' in document.documentElement.style) {
			window.addEventListener('hashchange', () => {
				var currentPath = window.location.hash.slice(1)
				if (this.$route.path !== currentPath) {
					this.$router.push(currentPath)
				}
			}, false)
		}
		return createElement(App);
	}
})

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章