Santosh Yadav
Santosh Yadav

Reputation: 51

not able to access data variable in methods in vuejs

In a Vue.js Project, I am not able to access a property => this.ws_files from a function inside methods. The property is accessible in mounted(), but not in methods.

Below is snippet of the code:

export default {   
  name: 'file-list',

  data () {
    return {
      title: pageName,
      ws_files: "AB"
    }
  },

  mounted () {
    this.getFolderInfo('ZEST/ZEST Negoce/',10)
  },

  methods: {
    getFolderInfo: (folderName,maxKeys) => {
      this.ws_files = "Sant"
    }
  }
}

Upvotes: 2

Views: 1325

Answers (1)

Decade Moon
Decade Moon

Reputation: 34286

Your issue is the same as this question.

You should not define the method using () => {} syntax.

Do this instead:

getFolderInfo(folderName, maxKeys) {
  this.ws_files = "Sant"
}

Upvotes: 4

Related Questions