Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binding v-model to a property #92

Open
hanspr opened this issue Jul 16, 2021 · 0 comments
Open

Binding v-model to a property #92

hanspr opened this issue Jul 16, 2021 · 0 comments

Comments

@hanspr
Copy link

hanspr commented Jul 16, 2021

I'm new to Vue so, maybe this is a known limitation of the Vue framework.

If I use vue-datepicker inside a page and bind v-model to a data property, everything works as expected.

<VueDatePicker v-model="data['date']"/>

data() {
  return {
    data: {
      date: new Date();
    },
  }
}

But if I place VueDatePicker inside another component and then bind v-model to the property:

<VueDatePicker v-model="data['date']"/>

props: {
  data: {
    type: Object,
    required: false,
    default: () => {}
  },
},
  • values are internally updated correctly
  • but the calendar ui does not update the changes
  • date is not updated in the input text box, cell in the calendar does not shows selected

Peek 16-07-2021 18-08


To make it work, I had to copy the property to a data object in the mounted method and bind v-model to the data (localdata property)

<VueDatePicker v-model="localdata['date']"/>

props: {
  data: {
    type: Object,
    required: false,
    default: () => {}
  },
},
data() {
  return {
    localdata: {}
  }
},

mounted() {
  this.localdata = Object.assign({},this.$props.data);
},

Peek 16-07-2021 18-10-2


So, am I doing it wrong?

This is how it has to be done?

Or, this could be fixed inside vue-datepicker to work properly with properties inside another component?

Thank you for your grate component.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant