title: Error - Uncaught (in promise) TypeError: Cannot read property 'data' of undefined
body: <p>I'm developing vue.js project and I got an error.</p>
  
  <blockquote>
    <p>Uncaught (in promise) TypeError: Cannot read property 'data' of undefined</p>
  </blockquote>
  
  <p>Here is the code.</p>
  
  <p>I passed form data to User class.</p>
  
  <p><strong>Login.vue</strong></p>
  
  <pre><code>&lt;script&gt;
   export default {
       data(){
           return {
               form :{
                   email:null,
                   password:null
               }
           }
      },
      methods:{
          login(){
              User.login(this.form)
          }
      }
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>and this is User class</p>
  
  <p><strong>User.js</strong></p>
  
  <pre><code>class User {
    login(data){
        axios.post('/api/auth/login',data)
            .then(res =&gt; this.responseAfterLogin(res))
            .catch(error =&gt; console.log(error.response.data))
    }
  }
  export default User = new User();
  </code></pre>
  
  <p>However, no error occured, when I moved login method to Login.vue and don't use User class.</p>
  
  <p><strong>Login.vue</strong></p>
  
  <pre><code> &lt;script&gt;
   export default {
       data(){
           return {
               form :{
                   email:null,
                   password:null
               }
           }
      },
      methods:{
          login(){
              axios.post('/api/auth/login',this.form)
              .then(res =&gt; console.log(res.data))
              .catch(error =&gt; console.log(error.response.data))
          }
      }
  }
   &lt;/script&gt;
  </code></pre>
  
  <p>Please explain why and how can I pass data to User class?</p>