I dont understand what is the difference between v-bind, v-modeland v-bind.sync?
Maybe it's too late, but I can't tell the difference between v-bind.syncand v-model after reading the documentation.
Passing Data to Child Components with Props
Example
I have the following component written in Typescript, using "vue-property-decorator". I don't know how I can manage to update the date object passed into the component without having to write the event handling myself. If you ask me, it should work with the v-model and with the v-bind.sync bindings (and respective changes in the markup and decorator).
HTML
<Datepicker v-model="date"/>
Typescript
import { Component, Prop, Vue, Model } from "vue-property-decorator";
@Component({})
export default class Datepicker extends Vue {
@Prop()
private label!: string;
@Model()
private date!: Date;
private internalDate = new Date().toISOString().substr(0, 10);
private menu = false;
private onDateChanged() {
const isoDate = this.date.toISOString();
const newDate =
this.internalDate + this.date.toISOString().substring(10);
this.date = new Date(newDate);
}
}
Every time I change the this.date object, I get the warning:
Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value. Prop being mutated: "date"