I am seeing a lot of conflicting documentation about Vue + Typescript component classes.
Where does one define properties? In the @Component annotation as outlined here? As @Prop annotated instance properties as outlined here?
Where does one initialized defined properties? In the constructor? In the field-level property definition?
Is there a definitive, up-to-date reference for these things, or an up-to-date sample app?
Here's what I have now:
<template>
<div class='contacts'>
<b-form @submit="search">
<b-form-group>
<b-form-input v-model="q"></b-form-input>
</b-form-group>
<b-button type="submit" variant="primary">Search</b-button>
</b-form>
<b-table :items='contacts'></b-table>
</div>
</template>
<script lang="ts">
import {Component, Prop, Vue} from 'vue-property-decorator'
@Component
export default class Contacts extends Vue {
constructor(options: any) {
super(options);
this.q = 'dummy data';
this.contacts = [{
'id': 1,
'first_name': 'Lukas',
'last_name': 'Stigers',
'email': null,
'gender': 'Male',
'phone': '776-878-7222'
}, {
'id': 2,
'first_name': 'Dari',
'last_name': 'Matkin',
'email': null,
'gender': 'Female',
'phone': '833-146-3305'
}]
}
@Prop() private q: string
@Prop() private contacts: any
search(event:Event) {
event.preventDefault();
alert('You searched for ' + this.q)
}
}
</script>
This works, but I'm receiving these warnings in the browser:
[Vue warn]: 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: "q"