index.js 731 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import {
  2. reactive,
  3. onMounted,
  4. getCurrentInstance
  5. } from 'vue'
  6. import {
  7. onReachBottom,
  8. onShow,
  9. onPullDownRefresh,
  10. onReady
  11. } from '@dcloudio/uni-app'
  12. export default loadmoreRef => {
  13. let refs = {}
  14. const refresh = () => {
  15. refs[loadmoreRef] && refs[loadmoreRef].refresh()
  16. }
  17. onMounted(() => {
  18. refs = getCurrentInstance().refs
  19. })
  20. onPullDownRefresh(() => {
  21. if (refs[loadmoreRef] && refs[loadmoreRef].pullDownRefresh) {
  22. refs[loadmoreRef].hasMore = true
  23. refs[loadmoreRef].query().then(() => uni.stopPullDownRefresh())
  24. }
  25. })
  26. onReachBottom(() => {
  27. if (refs[loadmoreRef] && refs[loadmoreRef].hasMore) {
  28. refs[loadmoreRef].query(true)
  29. }
  30. })
  31. return {
  32. refresh
  33. }
  34. }