vue组件 Javascript 换成 TypeScript 写法模板参考
vue组件写法
Vue组件模版来看: import {componentA,componentB} from '@/components'; export default { components: { componentA, componentB}, props: { propA: { type: Number }, propB: { default: 'default value' }, propC: { type: [String, Boolean] } } // 组件数据 data () { return { message: 'Hello' } }, // 计算属性 computed: { reversedMessage () { return this.message.split('').reverse().join('') } // Vuex数据 step() { return this.$store.state.count } }, methods: { changeMessage () { this.message = "Good bye" }, getName() { let name = this.$store.getters['person/name'] return name } }, // 生命周期 created () { }, mounted () { }, updated () { }, destroyed () { } }
vue使用TypeScript模板写法
以上模版替换成typescript修饰符写法则是: import { Component, Vue, Prop } from 'vue-property-decorator' import { State, Getter } from "vuex-class" import { count, name } from "@/person" import { componentA, componentB } from "@/components" @Component({ components: { componentA, componentB } }) export default class HelloWord extends Vue{ @Prop(Number) readonly propA!: number | undefined @Prop({default: "default value"}) readonly propB!:string @Prop([String, Boolean]) readonly propC!: string | boolean | undefined // 原data message = "Hello" // 计算属性 private get reversedMessage (): string[]{ return this.message.split('').reverse().join('') } // Vuex数据 @State ((state: IPootState) => state.booking.currentStep) step!:number @Getter("person/name") name!:name //methods public changeMessage():void{ this.message = "Good bye" } public getName(): string{ let storeName = name return storeName } // 生命周期 private created():void{}, private mounted():void{}, private updated():void{}, private destroyed():void{} }
相关推荐
QiaoranC 2020-09-25
ChaITSimpleLove 2020-10-06
ChaITSimpleLove 2020-07-26
iconhot 2020-07-05
changcongying 2020-11-02
changcongying 2020-10-30
苗疆三刀的随手记 2020-10-29
zouph000 2020-10-25
Jruing 2020-10-23
ctg 2020-10-14
PMJ0 2020-10-13
小飞侠V 2020-09-25
changcongying 2020-09-17
taizuduojie 2020-09-15
淼寒儿 2020-09-13
lyjava 2020-09-11
彤庆的技术 2020-09-02
锅哥 2020-08-27
ruanhongbiao 2020-08-16