gitakachan / vue-project-collections-and-issues

vue issues
0 stars 0 forks source link

錨點定位及跳轉(url不發生變化) #17

Open gitakachan opened 2 years ago

gitakachan commented 2 years ago

參考:https://www.itread01.com/content/1547429964.html

<a
    @click.prevent="returnTop(this.$refs.tapiei)"
    href="#"
    class="text-success"
    >台北
</a>

<!-- 按<a>跳轉至此 -->
 <div ref="tapiei">
    <h2>台北</h2> 
  </div>
  methods: {
    returnTop(ref) {
      ref.scrollIntoView(true);
    },
  },