usePages.ts 791 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { ref } from "vue";
  2. import { onPageScroll } from "@dcloudio/uni-app";
  3. /**
  4. * listPage页面公共方法
  5. *
  6. * @param options
  7. */
  8. export function usePages(type) {
  9. const NavBgColor = ref('transparent');
  10. const NavTitleStyle = ref()
  11. const initData = () => {
  12. switch (type) {
  13. case 1:
  14. NavTitleStyle.value = {
  15. color: '#fff'
  16. };
  17. NavBgColor.value = 'transparent';
  18. break;
  19. default:
  20. NavBgColor.value = 'transparent';
  21. }
  22. }
  23. onPageScroll((e) => {
  24. const { scrollTop } = e;
  25. if (scrollTop > 50) {
  26. console.log()
  27. switch (type) {
  28. case 1:
  29. NavTitleStyle.value = {};
  30. NavBgColor.value = "#fff";
  31. break;
  32. default:
  33. NavBgColor.value = "#fff";
  34. }
  35. } else {
  36. initData()
  37. }
  38. })
  39. initData()
  40. return { NavBgColor, NavTitleStyle }
  41. }