介紹vue
記錄開發過程當中的基礎用法。git
import { Vue, Component } from 'vue-property-decorator' import HelloWorld from './HelloWorld.vue' @Component({ components: { HelloWorld } }) export default class App extends Vue { }
import { Vue, Component, Prop } from 'vue-property-decorator' import HelloWorld from './HelloWorld.vue' @Component({ components: { HelloWorld } }) export default class App extends Vue { @Prop(String) name: string @Prop([Number, String]) score: number | string @Prop({ type: number, default: 18, required: true, validator: value => { return (value > 10 && value < 60) } }) age: number }
import { Vue, Component } from 'vue-property-decorator' @Component export default class App extends Vue { get calAge (newVal, oldVal) { return ((new Date()).getFullYear() - this.birthYear) } }
import { Vue, Component, Watch } from 'vue-property-decorator' @Component export default class App extends Vue { @Watch('birthYear', { immediate: true, deep: true}) onBirthYearChange (val: number, oldValue: number) { this.age = ( (new Date()).getFullYear() - val) } }