Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vue.js 如何使用vue路由器导航到顶部_Vue.js_Vue Router - Fatal编程技术网

Vue.js 如何使用vue路由器导航到顶部

Vue.js 如何使用vue路由器导航到顶部,vue.js,vue-router,Vue.js,Vue Router,有没有办法在同一页上使用vue路由器导航到{x:0,y:0}的顶部,而不使用“哈希”。我的代码如下 //.vue文件 <v-btn :to="{ name: 'publications', position: { x: 0, y: 0 } }">Top</v-btn> 您对此任务使用Vue路由器的要求是什么?您可以使用window.scrollTo()以更简单的方式实现它。 //router.js const router =

有没有办法在同一页上使用vue路由器导航到{x:0,y:0}的顶部,而不使用“哈希”。我的代码如下

//.vue文件

<v-btn
   :to="{
    name: 'publications',
    position: { x: 0, y: 0 }
}">Top</v-btn>

您对此任务使用Vue路由器的要求是什么?您可以使用
window.scrollTo()
以更简单的方式实现它。
//router.js
const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
  scrollBehavior(to) {
    if (to.hash) {
      return { selector: to.hash };
    } else {
      return { x: 0, y: 0 };
    }
  },
});