| | |
| | | export default { |
| | | data() { |
| | | return { |
| | | img_index:0, |
| | | anchor:false, |
| | | img_index: 0, |
| | | anchor: false |
| | | } |
| | | }, |
| | | mounted () { |
| | | let url = location.href |
| | | let hash = url.substring(url.length-9) |
| | | this.get_anchor(hash) |
| | | }, |
| | | watch: { //监听路由 |
| | | $route (to, from) { |
| | | if (to.params.hash && to.params.hash !== 'null') { |
| | | this.anchor = true |
| | | this.get_anchor(to.params.hash) |
| | | } |
| | | } |
| | | }, |
| | | methods: { |
| | | //根据hash值跳转不同锚点 |
| | | get_anchor (hash) { |
| | |
| | | } |
| | | } |
| | | }, |
| | | destroyed () { //返回顶部 |
| | | document.body.scrollTop = 0 |
| | | document.documentElement.scrollTop = 0 |
| | | }, |
| | | watch: { //监听路由 |
| | | $route (to,from) { |
| | | if (to.hash) { |
| | | this.anchor = true |
| | | this.get_anchor(to.hash) |
| | | } |
| | | mounted () { |
| | | let hash = this.$route.params.hash |
| | | if (hash && hash !== 'null') { |
| | | this.anchor = true |
| | | this.get_anchor(hash) |
| | | } |
| | | } |
| | | } |
| | | } |
| | | </script> |
| | | |