Laravel Vue更新数据

时间:2018-08-20 05:46:03

标签: laravel vue.js

我下面有代码,每5秒刷新一次数据

    methods:{
        update() {
           // my update info goes here
        },
        getInfo: function() { // here i'm getting current data from server (database)
                        let user_id = this.user.id;
                        axios.get('/api/show/'+ user_id).then((response) => {
                            this.info = response.data;
                            this.profile=Object.assign({},this.info);
                        });
                        setTimeout(this.getInfo, 5000);
                    },
        }
},
ready() {
   this.getInfo();
}

此代码的问题是每5秒有1个请求发送到我的后端(需要大量服务器*想象100个用户看到同一页面时,每秒有多少个请求发送到服务器)

因此,我正在寻找另一种选择,仅当我的更新请求update() {成功时才刷新我的数据,这样,只有当数据库中的数据发生更改时,我的数据才会刷新。

有什么主意吗?

更新

为了更好地理解我的工作方式...

one

0 个答案:

没有答案