【发布时间】:2019-02-26 09:25:44
【问题描述】:
不明白为什么这个简单的事情没有反应。 看起来我错过了一些 Vue 的基础。
<template>
<div>
{{connection_status}}
</div>
</template>
<script>
export default {
data() {
return {
connection_status: 'loading',
};
},
created() {
Echo.connector.socket.on('connect', function(){
this.connection_status = 'connected';
console.log(this.connection_status );
});
Echo.connector.socket.on('disconnect', function(){
this.connection_status = 'disconnected';
console.log(this.connection_status );
});
},
}
</script>
Echo 通过 socket.io 运行并且工作正常。所有事件都会及时触发。
连接时的控制台输出:
connected
但在页面上
loading
断开连接的触发器也是如此。 在控制台中:
disconnected
在页面上
loading
【问题讨论】:
标签: javascript vue.js socket.io vuejs2 reactive-programming