vue-property-decoratoを使わずにpropsに型をつけたかった際のメモ
Object
<script lang="ts">
import Vue, { PropType } from 'vue'
type Pet = {
name: string
}
export default Vue.extend({
props: {
pet: {
type: Object as PropType<Pet>,
required: true
}
},
mounted() {
// Type Pet
console.log(this.pet)
}
})
</script>
Array
<script lang="ts">
import Vue, { PropType } from 'vue'
type Pet = {
name: string
}
export default Vue.extend({
props: {
pets: {
type: Array as PropType<Pet[]>,
required: true
}
},
mounted() {
// Type Pet[]
console.log(this.pets)
}
})
</script>