• typescript里,.vue文件的template部分跟javascript一样无需修改
    • vue-cli通过vue-property-decorator装饰器来实现typescript

    一个标准的.vue文件:

    1. <template>
    2. //...
    3. </template>
    4. <script lang="ts">
    5. <script lang="ts">
    6. import { Component, Vue, Watch, Prop, Emit } from 'vue-property-decorator'//引入装饰器
    7. import { Dictionary } from 'vue-router/types/router'//引入Dictionary接口类型
    8. import { Form as ElForm, Input } from 'element-ui'
    9. import { UserModule } from '@/store/modules/user'//引入vuex
    10. import { isValidUsername } from '@/utils/validate'//引入方法
    11. import Cards from './components/Cards.vue'//引入组件
    12. export interface BillMsgQuery {//声明接口
    13. pageNo: number
    14. pageSize: number
    15. selectYxStoreId: number
    16. beginDateTime?:number
    17. endDateTime?:number
    18. }
    19. @Component({
    20. name: 'Index',
    21. components: {
    22. Cards
    23. }
    24. })
    25. export default class extends Vue {
    26. @Prop({ default: false }) private isdowning!: boolean;//父组件传参props
    27. private orederType=[//data
    28. { name: '全部', label: -1 },
    29. { name: '普通订单', label: 1 }
    30. ]
    31. @Watch('page', { deep: true })//watch
    32. private onPageChange(value: number) {
    33. if (value === 1) this.pageNo = 1
    34. }
    35. @Emit('update:pageSize')//emit
    36. private pageSizeHandle(val: number) {
    37. return val // return将要传递的值
    38. }
    39. public get currPageSize() {//computed
    40. return this.pageSize
    41. }
    42. public set currPageSize(val: number) {//computed
    43. // this.$emit("update:pageSize", val);
    44. console.log('pagechange')
    45. this.pageSizeHandle(val)
    46. }
    47. mounted() {//mounted,created...
    48. this.initData()
    49. }
    50. //methods
    51. private handleSizeChange(val: number,params:BillMsgQuery) {
    52. this.currPageSize = val //设置computed值
    53. // this.$emit("update:page", 1);
    54. this.pageSizeHandle(1)
    55. }
    56. }
    57. </script>