0

thisis undefined and do not point to the Vue component instance inside then method. Following is the code

import { mapActions, mapMutations, mapGetters } from "vuex";
data: () => ({
  id: null,
  title: "",
  description: ""
}),
computed: {
  ...mapGetters("post/poststore", ["getPostDetails"])
},
methods: {
  ...mapActions({
    postAction: "post/postAction"
  }),
  post() {
    this.postAction({
      id: this.id,
      title: this.title,
      description: this.description
    })
    .then(function(data) {
      if (data) {
        if (this.getPostDetails.postType == "article") { // **this** here is undfeined
          // Do something
        } else {
          // Do something
        }
      }
    })  
  }
}
Meena Chaudhary
  • 9,909
  • 16
  • 60
  • 94
  • `function(data) {...` is a callback. Use arrow function instead. – Estus Flask Feb 26 '20 at 07:46
  • do not work with arrow function as well .`.then(data => {` this too give the same undefined – Meena Chaudhary Feb 26 '20 at 07:46
  • It surely does, this is what arrows are for. It physically cannot become undefined with `.then(data => {`, `this` inside an arrow is always equal to `this` outside of it. You probably didn't rebuild the app or something like this. In case you still have problems with arrows, consider providing a way to replicate the problem. – Estus Flask Feb 26 '20 at 07:48

0 Answers0