I'm trying to get event data from the web3 API using events method. In my Vue app methods, I have a method, newDsoValue
, that will watch for the events from the beginning and also for every newly fired event.
The method works perfectly fine only for the first time (when I change something in the block of code and save).
But if I refresh the browser tab, it does not load past event instead it will only load new fired events.
The method I'm using to load event data is used to get events from smart contracts
written in solidity
and deployed on Ethereum blockchain. The API is web3:1.0.0-beta.37
to get the event data.
I already tried mounted hook but no luck.
I also tried clearing browser cache, using another browser but no luck.
If I manually call this method, using a button click, then it also works fine.
I used to log some value in the console just before and after the API call inside the method, the value is perfectly logged in the console on every page refresh. Only the past data is not loaded.
Inside my method, I'm pushing data into an array
. From debugging, I came to know that array is loaded with events only first time and if I refresh the page, the array becomes empty.
This is the method:
newDsoValue() {
AssetLoggingContract.events
.RejectSetValue({
fromBlock: 0
})
.on("data", event => {
this.testEvents.push(event);
console.log(this.testEvents.length);
})
.on("error", console.error);
},
I'm calling this method inside the created
as:
created() {
this.newDsoValue();
}
I want to run this method on page load and every time I refresh the page it should load all the previous events and also the newly fired events. any help to achieve this? thanks