最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

vue.js - PrimeVue - How to use reset emit to clear form? - Stack Overflow

programmeradmin9浏览0评论

I've been experimenting with PrimeVue and am trying to understand how to use their forms. They don't have any example of clearing the form fields. However, there is mention of a "reset" event in the docs under the API for the Forms component: /

It states these are "custom events used by the component's emit." I'm rusty on how emits work. If I wanted to add a simple "Reset" button next to the Submit button that would use this, how would I do that? (Using Vue3 composition API).

Would like a short example, perhaps modified from one their doc examples.

I've been experimenting with PrimeVue and am trying to understand how to use their forms. They don't have any example of clearing the form fields. However, there is mention of a "reset" event in the docs under the API for the Forms component: https://primevue.org/forms/

It states these are "custom events used by the component's emit." I'm rusty on how emits work. If I wanted to add a simple "Reset" button next to the Submit button that would use this, how would I do that? (Using Vue3 composition API).

Would like a short example, perhaps modified from one their doc examples.

Share Improve this question asked Feb 5 at 0:09 jreevesjreeves 1
Add a comment  | 

1 Answer 1

Reset to default 0

The mentioned part of the documentation describes event object that is available in submit handler, where reset stands for event.reset() method and not an event.

Form exposes form instance through slot props, which isn't properly documented. The documentation states that $form contains form field properties, but this information is outdated.

With the latest version it's supposed to be something like:

<Form v-slot="$form">
  ...
  <button type="button" @click="$form.reset()">
  ...

Or considering there's form template ref:

<Form ref="form">
  ...
  <button type="button" @click="form.reset()">
  ...
发布评论

评论列表(0)

  1. 暂无评论