Khairul Habib
Khairul Habib

Reputation: 471

Vue Js Mounted did not triggred onpage load

Not sure the reason why mounted is no triggered any function in it. tested by display 'ss' also cannot be print out when page is loaded.

export default {
  name: 'loads',
  components: {
    Overlay,
  },
  data() {
    return {
      subscribed: true,
    };
  },
computed: {
    filteredLocation() {
      return this.$store.getters['location/filterLocation'](this.searchTerm);
    },
  },
  methods: {
    checkSubscriptionValidity() {
      this.$store.dispatch('user/checkTrial').then((res) => {
        this.subscribed = res.data;
      });
    },
  },
  mounted() {
    console.log('ss');
    this.checkSubscriptionValidity();
  },
};

is there any other reason that can cause this mounted not triggered issues?

Upvotes: 1

Views: 635

Answers (1)

Please try this syntax:

  computed: {
    filteredLocation: () => {
      return this.$store.getters['location/filterLocation'](this.searchTerm);
    },
  },
  methods: {
    checkSubscriptionValidity: () => {
      this.$store.dispatch('user/checkTrial').then((res) => {
        this.subscribed = res.data;
      });
    },
  },
  mounted: () => {
    console.log('ss');
    this.checkSubscriptionValidity();
  },

enter image description here

Upvotes: 1

Related Questions