interview-answe icon indicating copy to clipboard operation
interview-answe copied to clipboard

188.[微信小程序]获取Uni-app页面路由的方式

Open webVueBlog opened this issue 5 years ago • 2 comments

[微信小程序]

webVueBlog avatar Apr 18 '20 06:04 webVueBlog

这时通过函数getcurrentpages获取当前页面栈的实例后调用page.route方法就能拿到了

var pages = getCurrentPages();  
var page = (pages[pages.length - 1]).route;  

webVueBlog avatar Apr 18 '20 06:04 webVueBlog

方法二: 用官方已经挂在的$mp变量获取,其实和上述方法基本上是一致的,只是方法被挂载在$mp

let curRoute  = this.$mp.page.route; // 直接获取当前页面路由

以下是this.$mp对象返回的对象,实际上就是当前页面的webview对象

webVueBlog avatar Apr 18 '20 06:04 webVueBlog