javascript 如何在单击 Vuetify 按钮时重新加载页面?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/51273862/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 09:29:14  来源:igfitidea点击:

How do I reload page on click of Vuetify Button?

javascriptvue.jssingle-page-applicationvuetify.js

提问by Jeff

I need to refresh the current page when a user clicks the refresh button. I'm using Vuetify to generate the button.

当用户单击刷新按钮时,我需要刷新当前页面。我正在使用 Vuetify 生成按钮。

<v-btn fab dark>
     <v-icon dark>refresh</v-icon>
</v-btn>

I know in place of the router I can specify <v-btn fab dark to="myDesiredPath"but I need to refresh whatever route the user is currently on.

我知道代替我可以指定的路由器,<v-btn fab dark to="myDesiredPath"但我需要刷新用户当前所在的任何路由。

I know in vanilla js I can use location.reload(), but I don't know how to feed that to the button on the user's click.

我知道在 vanilla js 中我可以使用 location.reload(),但我不知道如何将它提供给用户点击的按钮。

回答by LShapz

you can just create a method in Vue that runs the vanilla JS and then run that method @clickof the v-btn.

您可以在 Vue 中创建一个运行 vanilla JS 的方法@click,然后运行v-btn 的该方法。

methods: {
  reloadPage(){
    window.location.reload()
  }
}