Home > Web Front-end > JS Tutorial > body text

Example of vue2.0 simulated anchor point

亚连
Release: 2018-05-30 13:53:06
Original
1648 people have browsed it

Below I will share with you an example of vue2.0 simulation anchor point, which has a good reference value and I hope it will be helpful to everyone.

In the vue project, due to the use of routing jumps, it will be impossible to use the regular a tag with the anchor function of the ID.

Solution:

<a href="javascript:void(0)" rel="external nofollow" @click="goAnchor(&#39;#anchor&#39;)"> 灰啊灰啊我的骄傲放纵</a>
Copy after login

methods: {
 goAnchor(selector) {
  var anchor = this.$el.querySelector(selector)
  document.body.scrollTop = anchor.offsetTop
 }
}
Copy after login

17. 9. 20 Update: The above has a BUG in FireFox, the fix is ​​as follows:

methods: {
 goAnchor(selector) {
  var anchor = this.$el.querySelector(selector)
  document.body.scrollTop = anchor.offsetTop; // chrome
  document.documentElement.scrollTop = anchor.offsetTop; // firefox
 }
}
Copy after login

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

Vue uses mixins to implement compressed image code

Vue project internationalization vue-i18n installation and use Tutorial

Broadcasting and receiving of Vue2.0 events (observer mode)

The above is the detailed content of Example of vue2.0 simulated anchor point. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template