JavaScript Vue: Reasons to use props instead of referencing parent data?

In VueJS, I have seen different ways of accessing parent properties from a component. Say I want to use the parent property items in my component.

First way

The component has a props value bound to a parent property:

.js

Vue.component("example", {
  template: "<div></div>",
  props: ["myItems"]
});

.html

<example v-bind:my-items="items"></example>

Second Way

The child component accesses a parent's properties directly, like this:

this.$parent.items

Question

Is there a reason to use the more elaborate first method over the second? Is there an overhead to "duplicating" data like that, vs. accessing it directly when needed?

Answer:1

My application architecture is simple Front end using ionic-angularjs with backend nodejs interfacing with mongodb. My application will require ability to submit data related to reimbursement (say few ...

My application architecture is simple Front end using ionic-angularjs with backend nodejs interfacing with mongodb. My application will require ability to submit data related to reimbursement (say few ...

So I trying to Mock a date in my test, this is what I did : const mockDate = new Date('2018-01-01'); const backupDate = Date; beforeEach(() => { (global.Date as any) = jest.fn(() => ...

So I trying to Mock a date in my test, this is what I did : const mockDate = new Date('2018-01-01'); const backupDate = Date; beforeEach(() => { (global.Date as any) = jest.fn(() => ...

  1. mock date jest
  2. mock new date jest
  3. mock date.now jest
  4. mock date constructor jest
  5. mock current date jest
  6. mock date object jest
  7. mock global date jest
  8. moment mock date jest
  9. mock date gettime jest
  10. mock date function jest
  11. mock date javascript jest
  12. jest mock date timezone
  13. jest mock date toisostring
  14. jest mock date typescript
  15. jest mock date time
  16. jest mock date-fns
  17. jest mock date constructor typescript
  18. jest mock date class
  19. jest mock date tolocalestring
  20. jest mock date prototype

I have a string composed by several fields. Two of which will always vary in length. I could simply use substring if all fields have fixed lengths. Sample: ...

I have a string composed by several fields. Two of which will always vary in length. I could simply use substring if all fields have fixed lengths. Sample: ...

  1. javascript contains substring
  2. javascript check substring
  3. javascript check substring in string
  4. javascript contains substring ignore case
  5. javascript contains substring in string
  6. javascript check substring case insensitive
  7. javascript check substring exists
  8. javascript check substring exists in string
  9. javascript contains substring in array
  10. javascript check substring in array
  11. javascript contains substring function
  12. javascript contains substring es6
  13. js contains substring
  14. js check substring
  15. js check substring in string
  16. javascript matching substrings
  17. js substring matching

I've figured out how to create an object based on an array, now I'm trying to understand how to build an array back from that object. with the object { social: { children: { ...

I've figured out how to create an object based on an array, now I'm trying to understand how to build an array back from that object. with the object { social: { children: { ...

  1. create url array