Why doesn"t window.location.hash = this.$route.hash work
mounted() {
this.$route.hash && (window.location.hash = this.$route.hash)
// setTimeout(() => {
// console.log(this.$route.hash)
// this.$route.hash && (window.location.hash = this.$route.hash)
// }, 2000)
},
watch: {
"$route.hash"() {
setTimeout(() => {
console.log(this.$route.hash)
this.$route.hash && (window.location.hash = this.$route.hash)
}, 5000)
// this.$route.hash && (window.location.hash = this.$route.hash)
}
},
the following two situations will work
1.hash
watch: {
"$route.hash"() {
setTimeout(() => {
console.log(this.$route.hash)
this.$route.hash && (window.location.hash = this.$route.hash)
}, 5000)
// this.$route.hash && (window.location.hash = "-sharptest")
}
},
2. Write in the event
<template>
<a @click="pushState(url)"></a>
</template>
methods: {
pushState(url) {
window.location.hash = `-sharp${url.split("-sharp")[1]}`
}
}