引入socket

This commit is contained in:
lulu
2018-10-23 16:07:51 +08:00
committed by Nova
parent 673e4a11b7
commit 9bedf5dccf
8 changed files with 59 additions and 29 deletions

View File

@@ -36,7 +36,7 @@
<td>{{ props.item.height }}</td>
<td>{{ props.item.timestamp }}</td>
<td>{{ props.item.type }}</td>
<td>{{ props.item.id }}</td>
<td>{{ props.item.hash }}</td>
</template>
<template slot="no-results">
{{ $t('chain.tableNone') }}
@@ -64,7 +64,7 @@
<td>{{ props.item.height }}</td>
<td>{{ props.item.timestamp }}</td>
<td>{{ props.item.type }}</td>
<td>{{ props.item.id }}</td>
<td>{{ props.item.hash }}</td>
</template>
<template slot="no-results">
{{ $t('chain.tableNone') }}
@@ -85,17 +85,16 @@ import {
createNamespacedHelpers,
} from 'vuex'
import Vue from 'vue'
import store from '../store'
import VueSocketio from 'vue-socket.io'
import io from 'socket.io-client'
const { mapState, mapGetters, mapActions, mapMutations } = createNamespacedHelpers('chain')
Vue.use(VueSocketio, io('http://localhost:6842'), store)
export default {
name: 'Chain',
data(){
return {
blockList:[],
}
},
computed: {
...mapState([
'headers',
@@ -107,23 +106,28 @@ export default {
]),
...mapGetters([]),
},
created: async function(){
let result=await axios({
method:'post',
url:location.protocol+'//'+location.hostname+':6842/api/Block/getBlockList',
data: {config:{order:'height DESC'}}
})
this.blockList=result.data||[]
sockets: {
connect() {
console.log('socket connected')
},
newBlock(msg) {
this.addNewBlock(msg)
},
},
mounted() {
this.queryBlockList()
},
methods: {
...mapActions([
'queryBlockList',
'addNewBlock',
]),
...mapMutations([
'inputFilter',
'showModal',
'hideModal',
'addDesserts',
]),
},
}