I am using VueJS to display active users in a site. When a user becomes active, Pusher sends JSON with their details -
{
"token": "97LbfNs7pfPbzVLo",
"first_name": "Joe",
"last_name": "Smith",
"avatar": "http://demo.com/avatar.jpg",
"phone": "255-255-2555",
"available" : true,
"agencies": [
{
"name": "Some company",
"slug": "some-company"
}
]
}
When the user signs out, their token
is sent along with available: false
. I need to then remove them from my Vue data
array, this is where I am stuck.
Here is the Data array in my Vue JS (pretty basic):
data: {
responders: []
}
UPDATE
Here is a very basic idea of what I'm trying to accomplish, only from outside of the Vue methods
. Basically I just need to remove an item from the data array, I think this is more of a Javascript related issue more than it is specific to Vue.
@michaelsnowden made the suggestion to store users as objects instead of an array but I'm not sure how to accomplish this. I have attempted:
addUser: function() {
var user = {'asdasdasdop': {name: "Joe"}};
this.users.push(user);
}
Which gives me:
"users": [
{
"asdasdasdop": {
"name": "Joe"
}
}
],
But beyond this I cannot figure out how to access these values or remove an item from the array based on the token. Any help would be greatly appreciated - I've had no issues adding but cannot for the life of me figure out how to remove something.