頁面跳轉添加參數
wx.navigateTo({ url: `../deeddetail/deeddetail?id=${e.currentTarget.dataset.id}`, })
接收options
1,在onLoad里接收參數比較簡單
onLoad: function (options) { console.log(options.id) //options.參數名就可以取到 },
2,其他位置獲取參數及url可以寫成工具函數放到utils中:
/*獲取當前頁url*/ const getCurrentPageUrl=()=>{ let pages = getCurrentPages() //獲取加載的頁面 let currentPage = pages[pages.length-1] //獲取當前頁面的對象 let url = currentPage.route //當前頁面url return url } /*獲取當前頁參數*/ const getCurrentPageParam=()=>{ let pages = getCurrentPages() //獲取加載的頁面 let currentPage = pages[pages.length-1] //獲取當前頁面的對象 let options = currentPage.options //如果要獲取url中所帶的參數可以查看options return options } module.exports = { getCurrentPageUrl, getCurrentPageParam }
3,使用
import utils from '../../../utils/util' let url=utils.getCurrentPageUrl() let options=utils.getCurrentPageParam()