Get the return value from store.dispatch

Hello,
i need a value from $store.dispatch for refresh the item in the page when go to page from another page or when open app.

This is my code.

home.vue

<div class="demo-facebook-date">{{ total_info }}</div>
//...

data() {
    return {
      total_info: localStorage.total,
//...
methods: {
  onPageInit() {
      console.log('PAGE INIT');
      var self = this;
this.$store.dispatch('tot_card').then(function (response) { self.total_info = localStorage.total ; }).catch(function (error) { console.log(error); })

//...

store.js

		tot_card({dispatch}){
	    myDB.transaction(function(transaction) {
	      transaction.executeSql( 'SELECT is_sync FROM requests', [], function(tx, result) {
	        var tot = result.rows.length;
	        localStorage.setItem('total', tot);
	      },
	      function(error) {
	        alert("Error occurred while creating the table.");
	      });
	    }); //fine myDB
		},

How i do ?

Thanks in advance

i dont fully understand what you need.
but maybe returning a promise helps;

tot_card({dispatch}) {
  return new Promise((resolve, reject) => {
      myDB.transaction(function(transaction) {
        transaction.executeSql( 'SELECT is_sync FROM requests', [], (tx, result) => {
          var tot = result.rows.length
          localStorage.setItem('total', tot)
          resolve(tot)
        },
        err => {
          alert('Error occurred while creating the table.')
          reject(err)
        })
      }) //fine myDB
  })
}
1 Like

Perfect, Function.
I need a refresh a div every time when open a page.
Many thanks.
Have a good day.