So this is my user list component for Vue. Socket.io returns a list of currently active users for example [{name:Fluxed,rank:Admin}] and I want it to auto-update the element. How can I update the prop element then make it show a change?
Here is my code
<template>
<div id="app">
<div>
<div style="float:right;width:30%;border-left:1px solid black;padding:1%;">
<b>Users</b>
<b-list-group style="max-width: 300px;" >
<b-list-group-item class="align-items-center" v-for="value in userList2" v-bind:key="value.name" >
<b-avatar class="mr-3"></b-avatar>
<span class="mr-auto">{{ value.name }}</span>
<b-badge>{{ value.rank }}</b-badge>
</b-list-group-item>
</b-list-group>
<ul class="list-group">
</ul>
</div>
</div>
</div>
</template>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script>
import io from 'socket.io-client';
import $ from 'jquery'
var socket = io('http://localhost:4000');
socket.on('update', function (users){
this.userList = users;
console.log(this.userList)
})
import VueJwtDecode from "vue-jwt-decode";
export default {
name: 'app',
props: {
userList2: {
type: Array,
default: () => []
}
},
data() {
return {
user: {},
componentKey: 0,
userList: this.userList2,
};
},
created () {
// get socket somehow
socket.on('update', function (users){
console.log(this.userList)
this.userList = users;
console.log(this.userList)
})
},
methods: {
async getUserDetails() {
let token = localStorage.getItem("jwt");
let decoded = VueJwtDecode.decode(token);
let response = await this.$http.post("/update", decoded);
let urank = response.data.rank;
this.user = decoded;
this.user.rank = urank;
},
logUserOut() {
localStorage.removeItem("jwt");
this.$router.push("/");
},
},
}
</script>
How can I make the Vue bootstrap group item auto-update once a change happens with socket.io?