【问题标题】:Vue.js refresh page when tapping a button点击按钮时Vue.js刷新页面
【发布时间】:2021-03-26 04:38:01
【问题描述】:

我想在点击按钮时刷新页面 这是按钮在 html 中的外观 <button v-on:click="getUser()" :class='gender'>Get Random User</button>

下的js代码

const app = Vue.createApp({
    data() {
        return {
            firstName: 'John',
            lastName: 'Doe',
            email: 'John@Doe.com',
            gender: 'male',
            picture: 'https://picsum.photos/200',
            profile: 'Profile',
        }
    },
    methods: { 
    async getUser() {
            
        $forceUpdate();
            
    }
}
})
app.mount('#app')

【问题讨论】:

  • 你想在哪里刷新你的页面?
  • async getUser() { $forceUpdate(); }
  • 为什么要刷新页面?我问了这个问题,也许您正在寻找其他东西。
  • 我点击按钮,然后转到getUser() {}
  • 好吧,我明白了。但是为什么要刷新页面而不重新加载?

标签: html vue.js button onclick page-refresh


【解决方案1】:
 methods: {
    getUser() {
        window.location.reload()
    }
  }

【讨论】:

    猜你喜欢
    • 2012-12-08
    • 2014-04-10
    • 1970-01-01
    • 2013-10-10
    • 2015-07-05
    • 2016-11-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多