I am trying to display websocket messages received with index and total number. How can I display total dynamically?
<template>
<div>
<v-btn @click="clickButton">Test Websocket</v-btn>
<h1>Total webhooks : {{total}}</h1>
<ul v-for="(log,index) in logs" :key=index >
<li>{{index}} - {{ log }}</li>
</ul>
</div>
</template>
<script>
export default {
data () {
return {
logs: [],
newlog: '',
total:0
}
},
methods: {
clickButton: function () {
this.$socket.send('Let me ask you a questin.can u hear me???')
}
},
created () {
this.$options.sockets.onmessage = (data) => {
console.log(data)
this.logs.push(data.data)
}
},
}
</script>
You don't need a computed property there. You can simply use {{logs.length}} in instead of total
here is a sample fiddle
https://jsfiddle.net/czgnv53q/3/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With