[Vuejs]-How to pass property value between to instances of a component

0👍

The parent component should pass a prop to both data sub-components:

<datepicker
  :myValue="myValue"
  input-label="From"
  input-id="start-date"
  input-name="start_date"
  input-value="<%= group_discount.start_date %>"
  @change-date="changeDate"
>
</datepicker>
<datepicker
    :myValue="myValue"
    input-label="To"
    input-id="end-date"
    input-name="end_date"
    input-value="<%= group_discount.end_date %>">
</datepicker>

Then you can use that prop in a computed or method to validate if it contains a value or not and override the to or from value.

Edit: You can also use your emit strategy but you still need to pass a prop to one of the components so it can read the data. If you’ve never used props before read about them here: https://v2.vuejs.org/v2/guide/components-props.html

Leave a comment