Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

196
Views
Difference between 'button.disabled = true' and 'button.value.disabled = true'?

The code sample is for Vue3 composition API to handle a signup form. The intention is to disable the button after it's pressed until the singin code(omitted) gets called only once.

Why is submitButton.value used vs. just the submitButton?

setup() {

const submitButton = ref<HTMLButtonElement | null>(null);

//Form submit function
const onSubmitLogin = (values) => {

  //Disable button
  /* eslint-disable  @typescript-eslint/no-non-null-assertion */
  submitButton.value!.disabled = true; 
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

submitButton is a ref which is an object with a single property named value that has the actual element.

So this:

submitButton.disabled = true

Is a type error because the ref has no property named disabled.

Where this:

submitButton.value!.disabled = true; 

Gets the value of the ref (an HTMLButtonElement) and sets the disabled property of that button.

Read more about refs in the docs: https://vuejs.org/api/reactivity-core.html#ref


Lastly, you can avoid having to silence that warning with something like:

submitButton.value && (submitButton.value.disabled = true)

here you only assign the property if the value exists.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!