需求:点击导航栏的各个tab,跳转(滚动)到当前页面的具体位置
锚点定位的基础用法:
<template>
<div class="home">
<div class="home-body">
<Home1></Home1>
<Home2 id="home"></Home2>
</div>
<GFooter active="home"></GFooter>
</div>
</template>
import GFooter from '@/components/ext/GFooter.vue'
import Home1 from '@/components/modules/home/Home1.vue'
import Home2 from '@/components/modules/home/Home2.vue'
import { onMounted } from 'vue'
onMounted(() => {
// 此处用的是获取id方法,而不是ref方法。
document.getElementById('home').scrollIntoView()
})