[Vuejs]-Vue js – method does not change data

0πŸ‘

βœ…

this in logout function is not Vue instance You should use arrow function for that:

 logout: function () {
    axios({
      method: 'post',
      url: 'logout',
      baseURL: this.baseurl
    })
      .then(response => {
          console.log(`post logout: ${JSON.stringify(response)}`)
          this.user = null
          this.authd = !this.authd
          console.log(`logout: authorised is ${this.authd}`)
          console.log(`logout: user is ${this.user}`)       
        })    
        .catch(function (error) {
          console.log("logout has gone wrong" + error)
        })   
  },

Leave a comment