当前位置:网站首页>微信小程序获取当前页面的url和参数
微信小程序获取当前页面的url和参数
2022-08-11 00:10:00 【小任睡不醒`】
页面跳转添加参数
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()
边栏推荐
- LENS CRA和SENSOR CRA匹配问题解析
- "NIO Cup" 2022 Nioke Summer Multi-School Training Camp 3 DF Problem Solving
- HGAME 2022 Week1 writeup
- Difference Between Image Recognition and Semantic Segmentation
- Software Testing Certificate (1) - Software Evaluator
- YOLOv5的Tricks | 【Trick11】在线模型训练可视化工具wandb(Weights & Biases)
- sqlmap combined with dnslog fast injection
- [Excel knowledge and skills] Convert text numbers to numeric format
- 如何利用原生JS实现回到顶部以及吸顶效果
- HGAME 2022 Final Pokemon v2 writeup
猜你喜欢
Only lazy and hungry. You still don't understand the singleton pattern!
14. Thymeleaf
李彦宏拆墙交朋友,大厂“塑料友情”能否帮百度啃下硬骨头?
分布式.性能优化
91.(cesium之家)cesium火箭发射模拟
leetcode 前K个高频单词
学习Apache ShardingSphere解析器源码(一)
[Excel knowledge and skills] Convert numeric format numbers to text format
9. Rest style request processing
Design and implementation of flower online sales management system
随机推荐
从0开始设计JVM ,忘记名词跟上思路一次搞懂
[Excel knowledge and skills] Convert text numbers to numeric format
③ 关系数据库标准语言SQL 数据查询(SELECT)
Cache knowledge summary
② 关系数据库标准语言SQL 数据定义(创建、修改基本表)、数据更新(增删改)
IEEE的论文哪里可以下载?
Promote the high-quality development of denim clothing
Deep Learning Transformer Architecture Analysis
[21天学习挑战赛——内核笔记](五)——devmem读写寄存器调试
How to recover deleted files from the recycle bin, two methods of recovering files from the recycle bin
【redis】发布和订阅消息
10. Notes on receiving parameters
15. 拦截器-HandlerInterceptor
Web APIs BOM- 操作浏览器之综合案例
LeetCode_优先级队列_692.前K个高频单词
[C Language Chapter] Detailed explanation of bitwise operators (“<<”, “>>”, “&”, “|”, “^”, “~”)
① 数据库介绍 及 关系型数据库的关系代数表达式
12. 处理 JSON
2. Dependency management and automatic configuration
2. 依赖管理和自动配置