简体   繁体   English

是否可以在 Vue.js 中使用相同的按钮发布和更新?

[英]Is it possible to post and update with the same button in Vue.js?

I wrote a form with vue.js.我用 vue.js 写了一个表单。 This form has a submit button.这个表单有一个提交按钮。 I want to make the first record with this button and then update the information if the user requests it.我想用这个按钮制作第一条记录,然后在用户请求时更新信息。 Is this possible with the same button?这可以用同一个按钮吗?

i suggest you to compare the ID of your required info, as example:我建议您比较所需信息的 ID,例如:

onButtonClick(formValue) {
  if (this.info.id) {
    this.update(this.info.id, formValue);
  } else {
    this.create(formValue);
  }
}

in this logic you can says if you start with empty form without any record, the this.info.id will be null and will triggered your create function.在这个逻辑中,您可以说如果您以没有任何记录的空表单开始,则 this.info.id 将为空并触发您的创建功能。 if there's record before you start alter the form it will trigger update function如果在开始更改表单之前有记录,它将触发更新功能

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM