- 首先后台准备了二维码,后台会在二维码里面放入内容即是参数
- 我们接下来先讲原生的模拟开发工具环境
模式名称随意,启动页面我选首页,进入场景选着扫小程序码进入
然后选着二维码
原生代码如下
Page({
onLoad: function(options) {
// options 中的 scene 需要使用 decodeURIComponent 才能获取到生成二维码时传入的 scene
let scene = decodeURIComponent(options.scene)
console.log(scene)
}
})
这样控制台就能输出scene的字符串了
- 接下来我们看看taro框架如何输出参数
- 第一种模拟环境选着和原生一样的配置
然后taro代码如下
componentWillMount=()=>{
console.log(this.$router)
console.log(this)
console.log(this.$router.params.scene)
let scene = this.$router.params.scene
let data = {
scene:scene
}
let postData ={
data:data
}
setTimeout(()=>{ code(postData).then((res)=>{
console.log('pppp')
console.log(res)
})},2000)
}
taro是不用options的直接使用this里面的$router路由
那么接下来我们换成普通编译然后从这里进去
就可以在控制台看到输出的内容了