JavaScript How to avoid providing a dummy Vue data structure during initialization?

In my Vue-driven HTML I have the line

<span>Last updated on {{incident.LastUpdate[0].date}}</span>

data in the Vue instance is defined as

data: {
    incident: {}
}

In the course of the execution, incident is asynchonously loaded but during the initial page load I see

[Vue warn]: Error in render: "TypeError: Cannot read property '0' of undefined"
(...)
TypeError: Cannot read property '0' of undefined

This is understandable because the incident contents are not available yet. When they are abvailable, the page is displayed correctly. The error is therefore predictibe and temporary so I could just forget it.

I wanted however to silence it and initialized incident with some dummy data

data: {
        incident: {
            LastUpdate: [
                {
                    date: null
                }
            ]
        },
    },

The error is now gone but I feel that this is awkward way to solve it. It can also become cumbersome if there is a more data to initialize.

My question: what is the correct way to handle this problem in Vue? Dummy data as in my fix?

Answer:1

Suppose I have an array like this: var arr = []; arr["india"] = 7; arr["indonesia"] = 3; arr["usa"] = 1; [india: 7, indonesia: 3, usa: 1] I need to get an array like [india: (7/11*100), ...

Suppose I have an array like this: var arr = []; arr["india"] = 7; arr["indonesia"] = 3; arr["usa"] = 1; [india: 7, indonesia: 3, usa: 1] I need to get an array like [india: (7/11*100), ...

  1. calculate percentage from 2 numbers
  2. calculate percentage from two numbers
  3. calculate percentage from fraction
  4. calculate percentage from z score
  5. calculate percentage from total
  6. calculate percentage from ratio
  7. calculate percentage from number
  8. calculate percentage from decimal
  9. calculate percentage from pivot table
  10. calculate percentage from price
  11. calculate percentage from points
  12. calculate percentage from histogram
  13. calculate percentage from odds ratio
  14. calculate percentage from percentile
  15. calculate percentage from two numbers excel
  16. calculate percentage from mean and standard deviation
  17. calculate percentage from mg/ml
  18. calculate percentage from total amount
  19. calculate percentage from standard deviation
  20. calculate percentage from normal distribution

I just want to ask for an appropriate way to append new elements in jQuery. In the past, I tend to do string concatenation and then append to a div. However, sometimes my data contains special chars (...

I just want to ask for an appropriate way to append new elements in jQuery. In the past, I tend to do string concatenation and then append to a div. However, sometimes my data contains special chars (...

Given the following example: setTimeout(function name(){console.log(1)}, 1000) (callback) Is name() (the callback) considered a function declaration or a named function expression? I know that ...

Given the following example: setTimeout(function name(){console.log(1)}, 1000) (callback) Is name() (the callback) considered a function declaration or a named function expression? I know that ...

I have a Backbone.Marionette item view. It renders a list of items. I want to listen for the scoll event everytime somebody scrolls the list. I assumed this would work: events: { 'scroll ul': '...

I have a Backbone.Marionette item view. It renders a list of items. I want to listen for the scoll event everytime somebody scrolls the list. I assumed this would work: events: { 'scroll ul': '...

  1. capture scroll event javascript
  2. capture scroll event angular
  3. capture scroll event
  4. capture scroll event jquery
  5. capture scroll event angular 4
  6. capture scroll event js
  7. capture scroll event angularjs
  8. capture scroll event div
  9. react capture scroll event
  10. iframe capture scroll event
  11. capture mouse scroll event
  12. capture window scroll event
  13. extjs capture scroll event
  14. excel vba capture scroll event