Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Vuex get data in mounted

const store = new Vuex.Store({
  state: {
    globalCompanies: {
      test: null
    }
  },
  mutations: {
    setMe: (state, payload) => {
      state.globalCompanies.test = payload
    }
  },
  actions: {
    pretendFetch: ({commit}) => {
      setTimeout(() => {
        commit('setMe', 'My text is here!')
      }, 300)
    }
  }
})

new Vue({
  el: '#app',
  store,
  computed: {
    cp: function() { // computed property will be updated when async call resolves
      return this.$store.state.globalCompanies.test;
    }
  },
  watch: { // watch changes here
    cp: function(newValue, oldValue) {
      // apply your logic here, e.g. invoke your listener function
      console.log('was: ', oldValue, ' now: ', newValue)
    }
  },
  mounted() {
    this.$store.dispatch('pretendFetch');
    // console.log(this.cp, this.$store.state.globalCompanies.test); // null
    // var cn = this.$store.state.globalCompanies.test; // null
    // console.log(cn) // null
  }
})
Comment

PREVIOUS NEXT
Code Example
Javascript :: three js div over orbitcontrol 
Javascript :: 9.4.1.3. Update Expression¶ // Loops 
Javascript :: how to clear form fields in react after submit 
Javascript :: javascript substtgin 
Javascript :: facebook graph X-Hub-Signature 
Javascript :: always shouldComponentUpdate return false to make program fast and performant 
Javascript :: i need to add content-type accept form data using node.js in middelware 
Javascript :: when i send req upload image in node give Error: ENOENT: no such file or directory,ues multer 
Javascript :: connection string in static class 
Javascript :: check the constructor property to find out if an object is a Date (contains the word "Date"): 
Javascript :: kjk 
Javascript :: Amazon Cognito domain on amplify not pulling 
Javascript :: Unable to load schema from https json SchemaStore org eslintrc 
Javascript :: serverless unsupported function event 
Javascript :: CELEBRITY PROBLEM 2 gfg 7-18-21 
Javascript :: zoom and pan in d3.js 
Javascript :: Grunt--project configuration object--uglify 
Javascript :: google script delete line 
Javascript :: Upload literal unsupported graphql 
Javascript :: how to create a variable with a operator in javascript 
Javascript :: rewrite /src/App.js 
Javascript :: vue-jstree 
Javascript :: which element is focused javascript console 
Javascript :: networkx explore nodes 
Javascript :: how to go specific content in react single page by id 
Javascript :: convert componentDidUpdate into useEffect 
Javascript :: indonesia whatsapp formatter javascript 
Javascript :: Viewport ch. 
Javascript :: jquery slick remove white fade 
Javascript :: localStorage check 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =