[Vuejs]-Unexpected identifier on function creation – js

1👍

Thats not valid. created() is a own hook of vue and should be outside of methods.

const app = new Vue({
  el: "#app",
  data: {
    errors: [],
    name: null,
    age: null
  },
  methods: {
    checkForm: function(e) {
      if (this.name && this.age) {
        console.log(this.name);
        return true;
      }

      console.log(this.name);

      this.errors = [];

      if (!this.name) {
        this.errors.push("Name required.");
      }
      if (!this.age) {
        this.errors.push("Age required.");
      }

      e.preventDefault();
    }
  },
  async created() {
    console.log("instance created");
  }
});

Leave a comment