问题描述
比如后台管理系统修改了数据,前端的页面怎样才能及时的重新获取数据;
问题出现的环境背景及自己尝试过哪些方法
使用过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()
}
}
你期待的结果是什么?实际看到的错误信息又是什么?
希望大神可以解答下,或者给个其他的思路;最好能够在不刷新页面的情况下,数据库的数据变化了,能够重新请求接口。
worker轮询,当然最好的方案是websocket了