0

i want to show loading text when click submit button and before the form submit. i tried this code.

<button type="button" @click="addCustomers" 
:disabled="disableSubmitButton" class="btn btn-primary" style="float: 
right;" value="ADD CUSTOMER">{{customer.loading ? "Loading..." : "ADD 
CUSTOMER"}}</button> 

after i add a loading object in data.

data(){
  return {
    loading: false,
  }
} 

when i call to my click event function i add "loading = true" to display my loading text.

but this process not working. how can i show it. i don't want any spinner loading packages in vuejs. this is my click event function.

addCustomers(){
   customer.loading = true;
   axios.post(){
     ....
   }
}

1 Answer 1

3

the customer data element is not mentioned in data object property, so your code should be like :

 <button type="button" @click="addCustomers" 
 :disabled="disableSubmitButton" class="btn btn-primary" style="float: 
 right;" value="ADD CUSTOMER">{{loading ? "Loading..." : "ADD 
 CUSTOMER"}}</button> 

and in the methods:

 addCustomers(){
   this.loading = true;
    axios.post().then(res=>{
         this.loading=false;
       }).catch(err=>{
        //handle error
       })
  }
Sign up to request clarification or add additional context in comments.

2 Comments

can i add this to a timeout
i think that you want something like i did in my edited answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.