1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Vue.js]フォームからデータ登録後にフォームを初期化する

1
Last updated at Posted at 2019-11-26

データをフォームから送信後データが残っていると、同じデータを登録してしまう再度可能性が
あるため登録後はフォームを初期化する実装をしました。

コードは非同期でレスポンスが帰ってきた箇所のみしてあります。

vue.js
...
<script>

methods:

.....
save() {
this.save
response => {
this.dataReset() //レスポンスが返ってきたらデータを初期化
}

//初期化のデータを呼び出すメソッド
dataReset() {
 this.save.title = null,
 this.save.body = null
}

</script>

空のデータがセットされたメソッドを呼び出すことで登録後はフォームが初期化するようになります。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?