微信小程序 頁面跳轉傳遞值
微信小程序導航有兩種形式:一種是在寫在js中進行跳轉,另一種是寫在wxml頁面中進行跳轉。
1、js導航
(1)、wx.navigateTo(OBJECT) :保留當前頁面,跳轉到應用內的某個頁面,使用wx.navigateBack可以返回到原頁面。

wx.navigateTo({ url: 'test?id=1' }) 獲取傳遞的值:
//test.js Page({ onLoad: function(option){ console.log(option.id) } }) (2)、wx.redirectTo(OBJECT):關閉當前頁面,跳轉到應用內的某個頁面。

wx.redirectTo({ url: 'test?id=1' }) (3)、wx.navigateBack(OBJECT):關閉當前頁面,返回上一頁面或多級頁面??赏ㄟ^ getCurrentPages()) 獲取當前的頁面棧,決定需要返回幾層。
2、wxml導航
navigator:頁面鏈接。

注:navigator-hover默認為{background-color: rgba(0, 0, 0, 0.1); opacity: 0.7;}, <navigator/>的子節點背景色應為透明色
示例代碼:
/** wxss **/ /** 修改默認的navigator點擊態 **/ .navigator-hover { color:blue; } /** 自定義其他點擊態樣式類 **/ .other-navigator-hover { color:red; } <view class="btn-area"> <navigator url="navigate?title=navigate" hover-class="navigator-hover">跳轉到新頁面</navigator> <navigator url="redirect?title=redirect" redirect hover-class="other-navigator-hover">在當前頁打開</navigator> </view>
獲取頁面傳遞的值:
// redirect.js navigator.js Page({ onLoad: function(options) { this.setData({ title: options.title }) } }) 感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
新聞熱點
疑難解答