爱简收旧衣按件回收前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
907 B

1 week ago
  1. export default {
  2. data() {
  3. return {
  4. isRefreshing: false
  5. }
  6. },
  7. methods: {
  8. async refreshData() {
  9. if (this.isRefreshing) return
  10. this.isRefreshing = true
  11. try {
  12. // 如果页面有自己的刷新逻辑,优先使用页面的
  13. if (typeof this.onRefresh === 'function') {
  14. await this.onRefresh()
  15. } else {
  16. // 默认刷新逻辑
  17. await new Promise(resolve => setTimeout(resolve, 1000))
  18. }
  19. uni.showToast({
  20. title: '刷新成功',
  21. icon: 'success'
  22. })
  23. } catch (error) {
  24. console.error('刷新失败:', error)
  25. uni.showToast({
  26. title: '刷新失败',
  27. icon: 'none'
  28. })
  29. } finally {
  30. this.isRefreshing = false
  31. uni.stopPullDownRefresh()
  32. }
  33. }
  34. },
  35. onPullDownRefresh() {
  36. this.refreshData()
  37. }
  38. }