【问题标题】:this.$vuetify.goTo(0) not working inside v-navigation-drawer in vuetifythis.$vuetify.goTo(0) 在 vuetify 的 v-navigation-drawer 中不起作用
【发布时间】:2020-10-08 13:47:55
【问题描述】:

这是我的代码:

<template>
   ....
   <v-navigation-drawer app absolute width="340" permanent>

    ....
     <v-btn fab dark fixed bottom left color="primary" @click="$vuetify.goTo(0)">
        <v-icon>keyboard_arrow_up</v-icon>
     </v-btn>
    ...
   <v-navigation-drawer>

<template>

当我点击代码中所示的按钮时,它应该滚动到抽屉的顶部。但事实并非如此。谁能帮帮我?

【问题讨论】:

  • 为什么你认为它应该滚动到顶部?

标签: vue.js vuetify.js


【解决方案1】:

你需要申请container,这是options之一,用于滚动。如果你不提供这个,vuetify 不会知道把它放在你的导航抽屉里。

在导航抽屉中添加参考:

<v-navigation-drawer app absolute width="340" permanent ref="myNavDrawer">

您可以在脚本中分配元素,以便我们可以在goTo 中引用它:

mounted() {
  this.navDrawerContent = 
   this.$refs['myNavDrawer'].$el.querySelector('div.v-navigation-drawer__content');
}

然后对于你的按钮,像你一样传递0,但添加container

<v-btn ... @click="$vuetify.goTo(0, { container: navDrawerContent } )">

CODEPEN 供您参考。

【讨论】:

  • 非常感谢!拯救了我的一天!
猜你喜欢
  • 2019-02-25
  • 2019-01-09
  • 1970-01-01
  • 2019-02-26
  • 2020-04-16
  • 2021-10-23
  • 1970-01-01
  • 2018-10-08
  • 1970-01-01
相关资源
最近更新 更多