Laravel echo vue js here方法

时间:2016-09-26 13:57:15

标签: vue.js laravel-5.3 broadcasting

我的方法有一个问题vuejs,laravel echo。

广播频道

Broadcast::channel('task.*', function ($user, $taskId) {
    $task = Task::find($taskId);
    if ($task)
    {
        return ['id' => $user->id, 'name' => $user->name];
    }
});

刀片模板

<task-show inline-template :task="{{ json_encode($task) }}" :user-id="{{ auth()->user()->id }}" >
                        <ul>
                            <li v-for="viewer in viewersExceptMe">
                                @{{ viewer['name'] }}
                            </li>
                        </ul>
                        <div>
                            <table class="table table-bordered table-hover">
                                <tbody>
                                    <tr>
                                        <td>Task Name</td>
                                        <td>@{{  task['name'] }}</td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </task-show>

我的剧本

<script>
    export default{
        props : {
            task : Object,
            userId : Number
        },
        data : function () {
          return {
              viewers : []
          }
        },
        ready : function(){
            this.listen();
        },
        computed: {
            viewersExceptMe(){
                return _.reject(this.viewers, viewer => viewer.id == this.userId);
            }
        },
        methods : {
            listen(){
                Echo.join('task.' + this.task.id)
                    .here(viewers => {
                        this.viewers = viewers;
                    });
            }
        }
    }
</script>

在下图中,here方法不起作用,当用户离开信息页面时,查看者变量不会更新

enter image description here

0 个答案:

没有答案