navigator.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <template>
  2. <view>
  3. <page-head :title="title"></page-head>
  4. <view class="uni-padding-wrap uni-common-mt">
  5. <view class="uni-btn-v">
  6. <button @tap="navigateTo">跳转新页面,并传递数据</button>
  7. <button @tap="navigateBack">返回上一页</button>
  8. <button @tap="redirectTo">在当前页面打开</button>
  9. <button @tap="switchTab">切换到模板选项卡</button>
  10. <button @tap="reLaunch">关闭所有页面,打开首页</button>
  11. <!-- #ifdef APP-PLUS -->
  12. <button @tap="customAnimation">使用自定义动画打开页面</button>
  13. <!-- #endif -->
  14. <!-- #ifdef APP-PLUS || H5 -->
  15. <button @tap="preloadPage">预载复杂页面</button>
  16. <!-- #endif -->
  17. <!-- #ifdef APP-PLUS -->
  18. <button @tap="unPreloadPage">取消页面预载</button>
  19. <!-- #endif -->
  20. <!-- #ifdef APP-PLUS || H5 -->
  21. <button @tap="navigateToPreloadPage">打开复杂页面</button>
  22. <!-- #endif -->
  23. </view>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. const preloadPageUrl = '/pages/extUI/calendar/calendar'
  29. export default {
  30. data() {
  31. return {
  32. title: 'navigate'
  33. }
  34. },
  35. methods: {
  36. navigateTo() {
  37. uni.navigateTo({
  38. url: 'new-page/new-vue-page-1?data=Hello'
  39. })
  40. },
  41. navigateBack() {
  42. uni.navigateBack();
  43. },
  44. redirectTo() {
  45. uni.redirectTo({
  46. url: 'new-page/new-vue-page-1'
  47. });
  48. },
  49. switchTab() {
  50. uni.switchTab({
  51. url: '/pages/tabBar/template/template'
  52. });
  53. },
  54. reLaunch() {
  55. uni.reLaunch({
  56. url: '/pages/tabBar/component/component'
  57. });
  58. },
  59. customAnimation(){
  60. uni.navigateTo({
  61. url: 'new-page/new-vue-page-1?data=使用自定义动画打开页面',
  62. animationType: 'slide-in-bottom',
  63. animationDuration: 200
  64. })
  65. },
  66. preloadPage(){
  67. uni.preloadPage({
  68. url: preloadPageUrl,
  69. success(){
  70. uni.showToast({
  71. title:'页面预载成功'
  72. })
  73. },
  74. fail(){
  75. uni.showToast({
  76. title:'页面预载失败'
  77. })
  78. }
  79. })
  80. },
  81. unPreloadPage(){
  82. uni.unPreloadPage({
  83. url: preloadPageUrl
  84. })
  85. },
  86. navigateToPreloadPage(){
  87. uni.navigateTo({
  88. url: preloadPageUrl
  89. })
  90. }
  91. }
  92. }
  93. </script>