0

Vue is kicking an error in the console for "cannot read property (property name) of undefined". I've tried using v-if but still getting the error. It seems like the object doesn't exist or cannot be accessed like I have defined it, but I don't know why?

object defined in Vue as:

customerData:{
     address:{
          firstName:'',
          lastName:''
          }
     }

Html

 <div v-if="customerData.address.firstName">
      <input  v-model="customerData.address.firstName">
 </div>

What am I missing?

1 Answer 1

1

It looks like you're referencing the data option in your directive binding, I think you should do :

<div >
  <input  v-model="address.firstName">
</div>
Sign up to request clarification or add additional context in comments.

4 Comments

I just updated to clarify. object is "customerData.address.firstName"
ok you should check the existence of parent object like v-if="customerData.address."
If I look at the object using {{customerData.address.firstName}} notation the value appears. However, the error is still being thrown in the console. I have tried with v-if and same result. Ill fire up a fiddle.
Thanks for your help on this. I was not able to replicate on fiddle (everything worked fine). I found the bug in the code which was caused the customerData object being overwritten by the response to a request when the page loaded. The "address" was not present in this response and therefore created the error.

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.