[Vuejs]-How to bind "v-model" property in vue?

0👍

In data(){} you cannot assign in this way model: this.email so you need to assign it in mounted() {} hook, check the code below:

<script>
export default {
  data() {
    return {
      email: "",
      password: "",
      confirm_password: "",
      full_name: "",
      login: "",
      username: "",
      possible_inputs: []
    };
  },
  mounted() {
    this.possible_inputs = [
      {
        caption: "Full Name",
        type: "text",
        when: "signup",
        model: this.full_name
      }, {
        caption: "Email",
        type: "email",
        when: "signup",
        model: this.email
      }, {
        caption: "Email or Username",
        type: "text",
        when: "login",
        model: this.login
      }, {
        caption: "Username",
        type: "text",
        when: "signup",
        model: this.username
      }, {
        caption: "Password",
        type: "password",
        when: "always",
        model: this.password
      }, {
        caption: "Confirm Password",
        type: "password",
        when: "signup",
        model: this.confirm_password
      },
    ];
  },
};
</script>

Leave a comment