在POST中单击按钮名称

时间:2018-04-20 06:21:11

标签: vue.js

在Vue中,我尝试过命名按钮,但在提交后,数据不会发布。

   <div id="app">
      <form ref="myForm" method="POST" v-on:submit.prevent="onSubmit($event)" action="/push" class="needs-validation" id="myForm" novalidate="true">
        <div class="form-group">
          <label for="cannedListLabel">Canned List</label>
          <input v-model="cannedlist" ref="cannedlist" type="text" class="form-control" name="fileListFile" id="filelist"
         :disabled="!!individuallist" v-on:submit.prevent="onSubmit" />
        </div>
        <div class="form-group">
          <label for="pathListLabel">Path List</label>
          <textarea v-model="individuallist" ref="cannedlist" :disabled="!!cannedlist" class="form-control" rows=10 name="fileListRaw" id="files"></textarea>
        </div>            
        <div class="form-group">
          <button v-on:submit.prevent="onSubmit($event)" type="submit" name="button1" value="submit" id="submitButton" class="btn btn-primary" :disabled="isDisabledButton">Submit</button>
          <button v-model="clickedButton" v-on:submit.prevent="onSubmit($event)" type="submit" name="button2" value="checkOnly" id="checkOnlyButton" class="btn btn-primary" :disabled="isDisabledButton">Check Only</button>
        </div>
      </form>
    </div>

onSubmit函数使用此提交表单。$ refs.myForm.submit();如果我将按钮的类型从“提交”更改为“按钮”,则submit()函数不再有效,我不完全理解。顺便问一下为什么呢?

根据建议,我将类型更改为按钮,并使用@click处理程序,虽然它不起作用,但这里改变了差异:

        <div class="form-group">
          <button @click="onSubmit($event)" type="button" name="btn" value="submitButtonPressed" id="submitButton" class="btn btn-primary mb-2" :disabled="isDisabledButton">Submit</button>
          <button @click="onSubmit($event)" type="button" name="btn" value="checkOnlyButtonPressed" id="checkOnlyButton" class="btn btn-primary" :disabled="isDisabledButton">Check Only</button>
        </div>

0 个答案:

没有答案