tn-swipe-action.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <template>
  2. <view class="tn-swipe-action-class tn-swipe-action">
  3. <slot></slot>
  4. </view>
  5. </template>
  6. <script>
  7. export default {
  8. name: 'tn-swipe-action',
  9. props: {
  10. // 是否自动关闭其他swipe按钮组
  11. autoClose: {
  12. type: Boolean,
  13. default: true
  14. }
  15. },
  16. provide() {
  17. return {
  18. swipeAction: this
  19. }
  20. },
  21. computed: {
  22. // 用于监听父组件参数变化
  23. parentData() {
  24. return [this.autoClose]
  25. }
  26. },
  27. data() {
  28. return {}
  29. },
  30. watch: {
  31. parentData() {
  32. if (this.children.length) {
  33. this.children.map(child => {
  34. // 判断子组件(tn-swipe-action-item)如果有updateParentData方法的话,就就执行(执行的结果是子组件重新从父组件拉取了最新的值)
  35. typeof(child.updateParentData) === 'function' && child.updateParentData()
  36. })
  37. }
  38. }
  39. },
  40. created() {
  41. this.children = []
  42. },
  43. methods: {
  44. // 关闭其他单元格
  45. closeOther(child) {
  46. if (this.autoClose) {
  47. // 历遍所有的单元格,找出非当前操作中的单元格,进行关闭
  48. this.children.map((item, index) => {
  49. if (child !== item) {
  50. item.closeHandler()
  51. }
  52. })
  53. }
  54. }
  55. }
  56. }
  57. </script>
  58. <style>
  59. </style>