Get current page
1. In VUE (H5) Project:
this.$route.path // Routing path
this.$route.params // Route path parameters
this.$route.query // Route query parameters
Copy the code
2. Mpvue Project:
const pages = getCurrentPages() // Get the loaded page
const currentPage = pages[pages.length-1] // Get the object of the current page
// const url = currentpage.route // currentPage url
// const options = currentPage.options // If you want to get the parameters in the URL, see options
// console.log(options)
Copy the code
3. In uniAPP Project:
// If you need to reload the current page
// getCurrentPages().pop() gets the current page number and executes onLoad(or onShow, onReady) for the current page.
const currentPage =getCurrentPages().pop();
// if (currentPage == undefined || currentPage == null) return;
// currentPage.onShow();
Copy the code
Gets the page URL and parameters
1. In vUE project:
(1) Complete URL:
window.location.href
Copy the code
(2) Routing path:
this.$route.path
Copy the code
(3) Routing path parameters:
this.$route.params
Copy the code
Such as:
/ user / : - / user/id2044011030 → this.$route.params.id
Copy the code
(4) Route query parameters:
this.$route.query
Copy the code
Such as:
/user/search? Name = sf - >this.$route.query.name
Copy the code
2. In the UniAPP and MPVue project pages, the following methods can be used to obtain routing path parameters:
(1), unified to the parameters of onLoad, in fact, is the native small program to obtain:
onLoad(options) {
let {link,pms,title}=options
}
Copy the code
Currentpage.options = currentPage.options = currentPage.options = currentPage.options = currentPage.options
3. Mpvue project
(1) How to get the options passed by the applet when page onLoad
This is available in all page components via this.root.root.root.mp.query
(2) How to get the options passed by the applet during app onLaunch/onShow
Within all the components by enclosing the root, root, root, mp. AppOptions to obtain