因为你在哈希模式下使用路由,你将无法轻松滚动,因为滚动到/#something
实际上会将你重定向到"某物"页面.
您必须自己模拟滚动行为,try 这样做:
//P.S. the code is written for Vue 2.
//You will have to adjust it to Vue 1.
//Your view:
<a class="porto-button" @click="scrollMeTo('porto')">Porto, Portugal</a>
...
<div ref="porto" class="fl-porto">
//Your code:
methods: {
scrollMeTo(refName) {
var element = this.$refs[refName];
var top = element.offsetTop;
window.scrollTo(0, top);
}
}
工作原理:
- 将references to
ref
属性设置为要滚动到的元素;
- 编写一个函数,通过编程将
window.scrollY
设置为引用元素的top
.
- 工作完成:)
Update 1:
JSFIDLE https://jsfiddle.net/5k4ptmqg/4/
Update 2:
似乎在Vue 1 ref="name"
中看起来像el:name
(docs),下面是一个更新的示例:
https://jsfiddle.net/5y3pkoyz/2/