uni-app,跳轉和傳參


跳轉和傳參

  index頁 的代碼,寫了跳轉方式和傳值過程

 1 <template>
 2     <view class="content">
 3         <!-- url 后面加地址 -->
 4         <navigator url="../hello/hello" >
 5             <button type="primary" style="font-size: 40upx;">跳轉到Hello頁面(不是導航的頁面)</button>
 6         </navigator>
 7         
 8         <!-- 我們需要配置open-type="switchTab", 因為是底部導航欄, 跳轉需要額外配置 -->
 9         <navigator url="../guanyu/guanyu" open-type="switchTab" >
10             <button type="primary">跳轉到關於頁面(底部導航)</button>
11         </navigator>
12         
13         <!-- 配置: hover-class="navigator-hover"  跳轉到新窗口 -->
14         <navigator url="../test/test"  hover-class="navigator-hover">
15             <button type="primary">跳轉到test(新窗口)</button>
16         </navigator>
17         
18         <view class="" >
19             <button type="default" @click="skip">跳轉到新頁面</button>
20         </view>
21         
22         <!-- ? 后面加要傳的參數, 多個參數用 & 隔開 -->
23         <navigator url="../test/test?name=test1&age=19"  hover-class="navigator-hover">
24             <button type="default">跳轉傳值 navigator方式</button>
25         </navigator>
26         
27         <view class="" >
28             <button type="default" url="../test/test?name=test&age=18" @click="skip1()">跳轉傳值 @click方式</button>
29         </view>
30         
31         
32     </view>
33 </template>
34 
35 <script>
36     export default {
37         data() {
38             return {
39                 title: 'Hello'
40             }
41         },
42         methods: {
43             skip(){
44                 // API 形式的跳轉
45                 // <!-- uni.navigateTo(OBJECT):  保留當前的頁面, 跳轉到另一個頁面, 返回的話原來的頁面還會被保存-->
46                 // <!-- uni.rediretTO(OBJECT):  關閉當前頁面, 跳轉到另一個頁面 -->
47                 uni.navigateTo({
48                     //里面是一個對象形式的參數
49                     url: '../test/test'
50                 })
51             },
52             skip1(){
53                 uni.navigateTo({
54                     // ? 后面加要傳的參數, 多個參數用 & 隔開 
55                     url: '../test/test?name=test&age=18'
56                 })
57             }
58         }
59     }
60 </script>
61 
62 <style>
63     .content {
64         text-align: center;
65         height: 400upx;
66     }
67 
68     .logo {
69         height: 200upx;
70         width: 200upx;
71         margin-top: 200upx;
72     }
73 
74     .title {
75         font-size: 36upx;
76         color: #8f8f94;
77     }
78 </style>

 

text頁

 1 <template>
 2     <view>
 3         test
 4     </view>
 5 </template>
 6 
 7 <script>
 8     export default {
 9         data() {
10             return {
11                 
12             }
13         },
14         methods: {
15             
16         },
17         onLoad(options) {
18             //options可以接到index 傳過來的值
19             console.log(options)
20         },
21         // 當前頁面顯示3秒后, 返回上一級頁面
22         onShow() {
23             setTimeout(function(){
24                 uni.navigateBack({
25                     delta: 1
26                 })
27             }, 3000);
28         }
29     }
30 </script>
31 
32 <style>
33  
34 </style>

 

其他頁隨便寫點兒, 能看出來跳轉了就行

 

2019-06-13  10:17:45

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM