Z
Z
Zubastik_12017-10-16 18:04:37
Vue.js
Zubastik_1, 2017-10-16 18:04:37

How to apply two different methods to form submission - depending on the condition?

There is a form to which I apply the submit method

<textarea  v-on:keypress.enter.prevent="input.length && menMessage()" id="chat_msg" placeholder="" v-model="input"></textarea>

But for example, I want to send this form with this method only if the user is a man. And if the user is a woman, then the form will be sent using a different method.
<textarea  v-on:keypress.enter.prevent="input.length && womenMessage()" id="chat_msg" placeholder="" v-model="input"></textarea>

How to write it? Vue.js

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita Velko, 2017-10-16
@Zubastik_1

I wouldn't put all the logic in the event handler here.
And I would just make a method sendMessage()inside which I would check the user's gender and perform the necessary actions. But here already you will need to think about where and how you will store the user's gender.

methods: {
  sendMessage() {
    if (this.data.isMale) {
      // do something for men
    } else {
      // do something for women
    }
  },
},

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question