navigator.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 v-if="!hasLeftWin" @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. import { mapState } from 'vuex'
  30. export default {
  31. data() {
  32. return {
  33. title: 'navigate'
  34. }
  35. },
  36. computed: {
  37. ...mapState({
  38. hasLeftWin: state => !state.noMatchLeftWindow
  39. })
  40. },
  41. methods: {
  42. navigateTo() {
  43. uni.navigateTo({
  44. url: 'new-page/new-vue-page-1?data=Hello'
  45. })
  46. },
  47. navigateBack() {
  48. uni.navigateBack();
  49. },
  50. redirectTo() {
  51. uni.redirectTo({
  52. url: 'new-page/new-vue-page-1'
  53. });
  54. },
  55. switchTab() {
  56. uni.switchTab({
  57. url: '/pages/tabBar/template/template'
  58. });
  59. },
  60. reLaunch() {
  61. if (this.hasLeftWin) {
  62. uni.reLaunch({
  63. url: '/pages/component/view/view'
  64. });
  65. return;
  66. }
  67. uni.reLaunch({
  68. url: '/pages/tabBar/component/component'
  69. });
  70. },
  71. customAnimation(){
  72. uni.navigateTo({
  73. url: 'new-page/new-vue-page-1?data=使用自定义动画打开页面',
  74. animationType: 'slide-in-bottom',
  75. animationDuration: 200
  76. })
  77. },
  78. preloadPage(){
  79. uni.preloadPage({
  80. url: preloadPageUrl,
  81. success(){
  82. uni.showToast({
  83. title:'页面预载成功'
  84. })
  85. },
  86. fail(){
  87. uni.showToast({
  88. title:'页面预载失败'
  89. })
  90. }
  91. })
  92. },
  93. unPreloadPage(){
  94. uni.unPreloadPage({
  95. url: preloadPageUrl
  96. })
  97. },
  98. navigateToPreloadPage(){
  99. uni.navigateTo({
  100. url: preloadPageUrl
  101. })
  102. }
  103. }
  104. }
  105. </script>