Finish search bar

This commit is contained in:
liangping
2021-08-07 15:01:01 +08:00
parent 9d483c5a65
commit 6f7fcece61
3 changed files with 68 additions and 18 deletions
+26 -14
View File
@@ -66,24 +66,36 @@ export default {
],
}
},
beforeRouteUpdate(to, from, next) {
const { height } = to.params
if (height > 0 && height !== from.params.height) {
this.initData(height)
next()
}
},
created() {
const { height } = this.$route.params
this.$http.getBlockByHeight(height).then(res => {
this.block = res
const { txs } = res.block.data
const array = []
for (let i = 0; i <= txs.length; i += 1) {
try {
const origin = decodeTxRaw(fromBase64(txs[i]))
const tx = Tx.create(origin)
tx.setHash(txs[i])
array.push(tx)
} catch (e) {
this.initData(height)
},
methods: {
initData(height) {
this.$http.getBlockByHeight(height).then(res => {
this.block = res
const { txs } = res.block.data
const array = []
for (let i = 0; i <= txs.length; i += 1) {
try {
const origin = decodeTxRaw(fromBase64(txs[i]))
const tx = Tx.create(origin)
tx.setHash(txs[i])
array.push(tx)
} catch (e) {
// catch errors
}
}
}
if (array.length > 0) this.txs = array
})
if (array.length > 0) this.txs = array
})
},
},
}
</script>
+14 -1
View File
@@ -25,7 +25,10 @@
<b-tr>
<b-td>
{{ 'height' }}
</b-td><b-td>{{ tx.height }}</b-td>
</b-td><b-td>
<router-link :to="`../blocks/${tx.height}`">
{{ tx.height }}
</router-link></b-td>
</b-tr>
<b-tr>
<b-td>
@@ -103,6 +106,16 @@ export default {
tx: { tx: {} },
}
},
beforeRouteUpdate(to, from, next) {
const { hash } = to.params
console.log(hash !== from.params.hash, hash, from.params)
if (hash !== from.params.hash) {
this.$http.getTxs(hash).then(res => {
this.tx = res
})
next()
}
},
created() {
const { hash } = this.$route.params
this.$http.getTxs(hash).then(res => {