index.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <template></template>
  2. <script lang="ts">
  3. //vue-property-decorator的使用可以让开发人员以类的形式声明API
  4. import { Vue, Component, Watch, Prop } from "vue-property-decorator";
  5. import UserDoc from "@/views/currentSystem/components/UserDoc/index.vue";
  6. import Todos from "@/views/currentSystem/components/Todo/index.vue";
  7. import Alarm from "@/views/currentSystem/components/Alarm/index.vue";
  8. import UserTop from "@/views/currentSystem/components/UserTop/index.vue";
  9. import mixin from "./mixins/mixin";
  10. @Component({
  11. /**
  12. * 指定 name 选项的另一个好处是便于调试
  13. */
  14. name: "EXAMPLE",
  15. /**
  16. * Vue实例的可用组件
  17. */
  18. components: { UserDoc, Todos, Alarm, UserTop },
  19. /**
  20. * Vue实例的可用过滤器
  21. */
  22. filters: {
  23. formatteAuditStatus(val) {
  24. switch (val) {
  25. case "0":
  26. return "不同意";
  27. case "1":
  28. return "未审核";
  29. case "2":
  30. return "同意";
  31. }
  32. },
  33. },
  34. /**
  35. * Vue实例混入对象的数组
  36. */
  37. mixins: [mixin],
  38. })
  39. export default class Example extends Vue {
  40. /**
  41. * Vue实例的数据对象data中的属性
  42. */
  43. id:number=1
  44. code:string='示例文件'
  45. list:number[]=[1,2,3,4]
  46. /**
  47. * propA number类型, !表示一定有值
  48. */
  49. @Prop(Number) propA!:number
  50. /**
  51. * propB number类型,默认值为1
  52. */
  53. @Prop({default:1}) propB:number
  54. /**
  55. * propC类型为string或者number
  56. */
  57. @Prop([String,Boolean]) propC:string|boolean
  58. /**
  59. * 监听对象 括号中的$route等于this.$route
  60. */
  61. @Watch('$route')
  62. routeChange(newValue,oldValue){
  63. // 代码
  64. }
  65. /**
  66. * 监听对象 括号中的code等于this.code
  67. */
  68. @Watch('code',{immediate:true,deep:true})
  69. codeChange(newValue:string,oldValue:string){
  70. // 代码
  71. }
  72. /**
  73. * compute计算属性使用get,set标签
  74. */
  75. get computeA(){
  76. return this.code
  77. }
  78. set computed(code:string){
  79. this.code=code
  80. }
  81. /**
  82. * Vue生命周期函数
  83. */
  84. mounted() {
  85. // 代码
  86. }
  87. /**
  88. * 实例方法,无返回值
  89. */
  90. menthodA():void{
  91. }
  92. /**
  93. * 实例方法,返回值为字符串
  94. */
  95. menthodB(name:string):string{
  96. //代码
  97. return name
  98. }
  99. }
  100. </script>
  101. <style lang="scss" scoped>
  102. </style>