Guest User

Untitled

a guest
Feb 17th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. <template>
  2. <div>
  3. <slot/>
  4. </div>
  5. </template>
  6.  
  7. <script>
  8. // @ts-check
  9.  
  10. /**
  11. * @typedef {Object} SampleObjectProp
  12. * @property {number} key1 // mandatory
  13. * @property {string} [key2] // optional
  14. *
  15. * @typedef {Object} MyComponentData
  16. * @property {boolean} data1
  17. * @property {number} data2
  18. * @property {string} data3
  19. */
  20.  
  21. export default {
  22. name: 'MyComponent',
  23. props: {
  24. prop1: Boolean,
  25. prop2: {
  26. type: Number,
  27. default: 10
  28. },
  29. prop3: {
  30. type: String,
  31. default: 'foo'
  32. },
  33. prop4: {
  34. /** @type {{ (): string[] }} */
  35. type: Array,
  36. /** @type {{ (): string[] }} */
  37. default: () => []
  38. },
  39. prop5: {
  40. /** @type {{ (): SampleObjectProp }} */
  41. type: Object,
  42. /** @type {{ (): SampleObjectProp }} */
  43. default: () => ({ key1: 0 })
  44. }
  45. },
  46. /** @type {{ (): MyComponentData }} */
  47. data () {
  48. return {
  49. data1: true,
  50. data2: 0,
  51. data3: ''
  52. }
  53. },
  54. computed: {
  55. /** @returns {number} */
  56. myDouble () {
  57. return 2 * this.data2
  58. },
  59. /** @returns {string} */
  60. myHello () {
  61. return `Hello, ${this.data3}!`
  62. }
  63. },
  64. methods: {
  65. /** @param {boolean} value */
  66. setData1 (value) {
  67. this.data1 = value
  68. },
  69. /** @param {number} value */
  70. setData2 (value) {
  71. this.data2 = value
  72. },
  73. /** @param {string} value */
  74. setData3 (value) {
  75. this.data3 = value
  76. },
  77. /** @param {string} name */
  78. greet (name) {
  79. return `${this.myHello} How are you, ${name}?`
  80. }
  81. }
  82. }
  83. </script>
  84.  
  85. <style>
  86. </style>
Add Comment
Please, Sign In to add comment