diy-tab.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <template id="diy-tab">
  2. <div flex="cross:center">
  3. <div v-for="(item,index) in value" :key="index">
  4. <div @click="select(item,index)" style="cursor: pointer;">
  5. <slot :item="item" :index="item" :is-select="index == current"></slot>
  6. </div>
  7. </div>
  8. </div>
  9. </template>
  10. <script>
  11. Vue.component('diy-tab', {
  12. name: "diy-tab",
  13. template: "#diy-tab",
  14. props: {
  15. // 数据列表
  16. value: {
  17. type: Array,
  18. default () {
  19. return []
  20. }
  21. },
  22. // 默认选中
  23. defaultIndex: {
  24. type: Number | String,
  25. default () {
  26. return -1
  27. }
  28. },
  29. // 默认样式
  30. defaultStyle: {
  31. type: Object,
  32. default () {
  33. return {}
  34. }
  35. },
  36. // 选中样式
  37. selectedStyle: {
  38. type: Object,
  39. default () {
  40. return {}
  41. }
  42. },
  43. },
  44. data() {
  45. return {
  46. current: -1
  47. }
  48. },
  49. watch: {
  50. defaultIndex: {
  51. handler(newVal) {
  52. this.current = newVal
  53. },
  54. immediate: true,
  55. }
  56. },
  57. methods: {
  58. select(item, index) {
  59. this.current = index
  60. this.$emit("change", item, index)
  61. },
  62. }
  63. });
  64. </script>
  65. <style>
  66. .diy-tab-item {
  67. padding: 10px;
  68. }
  69. </style>