---
title: Check for Null/Undefined Before Accessing Properties in v-if
impact: MEDIUM
impactDescription: Accessing properties on null/undefined causes runtime errors and crashes
type: capability
tags: [vue3, conditional-rendering, v-if, null-check, defensive-programming]
---
# Check for Null/Undefined Before Accessing Properties in v-if
**Impact: MEDIUM** - Accessing properties on null or undefined objects in `v-if` conditions causes "Cannot read property of undefined" runtime errors. This commonly occurs when data is loaded asynchronously or when optional object properties are accessed without null checks.
## Task Checklist
- [ ] Always check that an object exists before accessing its properties
- [ ] Use optional chaining (?.) in Vue 3 templates for cleaner null checks
- [ ] Consider using computed properties for complex conditional logic
- [ ] Handle loading states explicitly rather than relying on undefined checks
**Incorrect:**
```html
Admin Panel
```
```html
Local delivery available
```
```html
{{ items[0].description }}
```
**Correct:**
```html
Admin Panel
```
```html
Admin Panel
```
```html
Local delivery available
```
```html
{{ items[0].description }}
{{ items[0].description }}
```
```html
Loading...
Error: {{ error.message }}
Welcome, {{ user.name }}
Admin Panel
No user data
```
## Using Computed Properties for Complex Checks
```javascript
// CORRECT: Move complex checks to computed properties
Admin Panel
{{ userDisplayName }}
```
## Common Async Data Pattern
```javascript
// CORRECT: Handle async data loading properly
Loading user...
Failed to load user
{{ user.name }}
{{ user.bio }}
```
## Reference
- [Vue.js Conditional Rendering](https://vuejs.org/guide/essentials/conditional.html)
- [MDN - Optional Chaining](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining)