账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    vue中去数据库请求回来数据,如果数据库数据发生变化,页面怎样可以自动变化
    53
    0

    问题描述

    比如后台管理系统修改了数据,前端的页面怎样才能及时的重新获取数据;

    问题出现的环境背景及自己尝试过哪些方法

    使用过vue的set,watch,computed也是没能解决

    相关代码

    // 请把代码文本粘贴到下方(请勿用图片代替代码)

    <template>

    <div id="app">
        <p>{{id}}</p>
        <router-view/>
    </div>

    </template>

    <script>

    export default {
        name: 'App',
        data() {
            return {
                id: 'images_show'
            }
        },
        methods: {
            getRouterLink () {
                this.$axios.get('http://192.168.0.182:8084/Temp/temp1').then(
                    res => {
                        console.log(res.data,);
                        this.id = res.data;
                        if (this.id === 'images_show') {
                            this.$router.push('/')
                        } else if (this.id === 'change_video') {
                            this.$router.push('/media')
                        } else if (this.id === 'change_luck') {
                            this.$router.push('/random')
                        } else if (this.id === 'change_photoes') {
                            this.$router.push('/voice')
                        }else if (this.id === 'change_voice') {
                            this.$router.push('/admin')
                        }
                    }
                ).catch(
                    err => {
                        console.log(err);
                    }
                );
    
            }
        },
        created() {
            this.getRouterLink()
        }
    }

    你期待的结果是什么?实际看到的错误信息又是什么?

    希望大神可以解答下,或者给个其他的思路;最好能够在不刷新页面的情况下,数据库的数据变化了,能够重新请求接口。

    2
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 大罗阎王 普通会员 1楼
      502 Bad Gateway

      502 Bad Gateway


      nginx
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部