Socket.io 等待作业完成以在vuejs中渲染组件
我这里有一个组件,我需要首先使用socket.io发出请求:Socket.io 等待作业完成以在vuejs中渲染组件,socket.io,vue.js,Socket.io,Vue.js,我这里有一个组件,我需要首先使用socket.io发出请求: <template> <h1>Don't show me before the socket's response</h1> </template> <script> export default { beforeCreate: function() { let sessid = this.$cookie.get('s
<template>
<h1>Don't show me before the socket's response</h1>
</template>
<script>
export default {
beforeCreate: function() {
let sessid = this.$cookie.get('sessid')
this.$options.sockets.logout = (data) => {
if (data.redirect) {
this.$router.push(data.redirect)
} else {
console.log('here, you can render the template')
}
}
this.$socket.emit('logout', { sessid })
}
}
</script>
在套接字响应之前不要显示我
导出默认值{
beforeCreate:function(){
设sessiond=this.$cookie.get('sessiond'))
这是。$options.sockets.logout=(数据)=>{
if(data.redirect){
此.$router.push(数据.重定向)
}否则{
log('在这里,您可以呈现模板')
}
}
此.$socket.emit('logout',{sessiond})
}
}
这段代码可以工作,但在重定向发生之前,它会在浏览器中快速显示模板
我想知道是否有一个记号等待套接字响应来呈现模板。当套接字响应到达时,您可以使用一个变量,该变量可以与v-if一起使用,以不显示HTML,如下所示:
<template>
<h1 v-if="sockResp">Don't show me before the socket's response</h1>
</template>
<script>
export default {
data: function() {
return {
sockResp: false
}
},
beforeCreate: function() {
let sessid = this.$cookie.get('sessid')
this.$options.sockets.logout = (data) => {
if (data.redirect) {
this.$router.push(data.redirect)
} else {
console.log('here, you can render the template')
this.sockResp = true
}
}
this.$socket.emit('logout', { sessid })
}
}
</script>
在套接字响应之前不要显示我
导出默认值{
数据:函数(){
返回{
sockrep:false
}
},
beforeCreate:function(){
设sessiond=this.$cookie.get('sessiond'))
这是。$options.sockets.logout=(数据)=>{
if(data.redirect){
此.$router.push(数据.重定向)
}否则{
log('在这里,您可以呈现模板')
this.sockrep=true
}
}
此.$socket.emit('logout',{sessiond})
}
}