div 的 Vue 路由器
Vue Router for a div
我有一个 home.vue 组件,在模板中我有多个 div 的 class 名称和 ID,我有我想单击并使用 class 名称或 ID 路由到某个 div 的导航链接是否仍然可以使用 vue-router 来完成?
我尝试使用
<li><router-link to="#about" >About Us</router-link></li>
用于将其路由到 #aboutus id
的 div
但我做不到,我搜索了互联网,没有找到任何有用的资源帮助我。
check out the imgur image here
为此您不需要 vue 路由器。您所做的只是尝试滚动到页面上的 div,所以为什么不尝试这样的操作:
<li>
<a href="#" @click.prevent="goToDiv"><span>Go To</span></a>
</li>
并在您的脚本中:
methods: {
goToDiv() {
var elmnt = document.getElementById("yourId");
elmnt.scrollIntoView();
},
}
我有一个 home.vue 组件,在模板中我有多个 div 的 class 名称和 ID,我有我想单击并使用 class 名称或 ID 路由到某个 div 的导航链接是否仍然可以使用 vue-router 来完成?
我尝试使用
<li><router-link to="#about" >About Us</router-link></li>
用于将其路由到 #aboutus id
的 div
但我做不到,我搜索了互联网,没有找到任何有用的资源帮助我。
check out the imgur image here
为此您不需要 vue 路由器。您所做的只是尝试滚动到页面上的 div,所以为什么不尝试这样的操作:
<li>
<a href="#" @click.prevent="goToDiv"><span>Go To</span></a>
</li>
并在您的脚本中:
methods: {
goToDiv() {
var elmnt = document.getElementById("yourId");
elmnt.scrollIntoView();
},
}