OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How to apply :loading in dynamically created button through v-for in Vue js

  • Thread starter Thread starter user1896653
  • Start date Start date
U

user1896653

Guest
Here is the demo response from the API:

Code:
[
    {
      form_name: 'Form One',
      name: 'Peter',
      email: '[email protected]'
    },
    {
      form_name: 'Form Two',
      name: 'John',
      email: '[email protected]'
    }
  ]

From that I built a form through v-for

Code:
<v-form 
   v-for="(item, index) in forms" :key="index"
>
  <v-btn
    :loading="saveLoading"
    @click="submit(item)"
  >
    submit
  </v-btn>
</v-form>

I set saveLoading: false, initially. In the submit(item) function, I was setting saveLoading: true, at first. Then at asynchronous function for POST method, I would turned that back to false. But, the problem is whenever, I click on the submit button in one form, two submit buttons in the two form got affected by loading state. enter image description here

What to do to get the effect in one submit button for the current form only?

Codepen Demo

<p>Here is the demo response from the API:</p>
<pre><code>[
{
form_name: 'Form One',
name: 'Peter',
email: '[email protected]'
},
{
form_name: 'Form Two',
name: 'John',
email: '[email protected]'
}
]
</code></pre>
<p>From that I built a form through <code>v-for</code></p>
<pre><code><v-form
v-for="(item, index) in forms" :key="index"
>
<v-btn
:loading="saveLoading"
@click="submit(item)"
>
submit
</v-btn>
</v-form>
</code></pre>
<p>I set <code>saveLoading: false,</code> initially. In the <code>submit(item)</code> function, I was setting <code>saveLoading: true,</code> at first. Then at asynchronous function for POST method, I would turned that back to <code>false</code>. But, the problem is whenever, I click on the <code>submit</code> button in <strong>one form</strong>, <strong>two <code>submit</code> buttons</strong> in the <strong>two form</strong> got affected by loading state.
<a href="https://i.sstatic.net/PAUnX.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/PAUnX.jpg" alt="enter image description here" /></a></p>
<p>What to do to get the effect in one <code>submit</code> button for the current form only?</p>
<p><strong><a href="https://codepen.io/lr_73/pen/jOGwowr?editors=101" rel="nofollow noreferrer">Codepen Demo</a></strong></p>
 

Latest posts

S
Replies
0
Views
1
Sergey Bakaev Rettley
S
Top