Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
372 views
in Technique[技术] by (71.8m points)

vue.js - Button does not invoke my method in vuejs when clicked

Method submitReg() should trigger when the button p-button is clicked, but it doesn't. I have two submit buttons at the bottom of my form. The one called "add" which works, but the Request Access does not invoke the submitReg() method, why?

          <form v-on:submit="submitReg">
          <fg-input v-model="form.email" addon-left-icon="nc-icon nc-email-85" placeholder="Email..."></fg-input>
          <fg-input v-model="form.password" type="password" addon-left-icon="nc-icon nc-key-25" placeholder="Password..."></fg-input>
          <p-checkbox class="text-left" v-model="form.acceptTerms">
            I agree to the
            <a href="#something">terms and conditions</a>.
          </p-checkbox>

          <p-button slot="footer" type="submit" round>Request Access</p-button>
          <button slot="footer"  type="submit">Add</button>

methods

methods: {
submitReg(e) {
    console.log(this.form.email);
    alert("here")
  },
  toggleNavbar() {
    document.body.classList.toggle('nav-open')
  },
  closeMenu() {
    document.body.classList.remove('nav-open')
    document.body.classList.remove('off-canvas-sidebar')
  }
},
question from:https://stackoverflow.com/questions/65921403/button-does-not-invoke-my-method-in-vuejs-when-clicked

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try this :

  1. change <form v-on:submit="submitReg"> by <form @submit.prevent="submitReg">
  2. change submitReg(e){ console.log(this.form.email); alert("here") }, by submitReg(){ alert("here") },

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...