Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何手动清空this.$router.param? #4032

Closed
mingsong2 opened this issue Aug 1, 2019 · 9 comments
Closed

如何手动清空this.$router.param? #4032

mingsong2 opened this issue Aug 1, 2019 · 9 comments
Assignees
Labels
question Further information is requested

Comments

@mingsong2
Copy link

问题描述
使用this.$router.params来获取小程序码中携带的参数,但是发现在'ios设备中', this.$router.params中的参数在生命周期中一直存在,页面跳出后,该参数一直存在。安卓设备中没有这个问题, 安卓设备中this.$router.params中的参数只在第一次扫小程序码的时候有,页面跳出再次进入后便没有改参数。请问:如何手动清空this.$router.params?

复现步骤

componentDidMount(){
   var { store_id, q, scene } = this.$router.params;
   if (store_id){
       await Store.setCurrentStore(store_id);
   }  
}
第一次通过扫描小程序码进入该页面后,会从`this.$router.params`中解析出store_id;
但是,在ios设备中,再次进入该页面后,this.$router.params.store_id依然存在,请问如何手动清除this.$router.params.store_id ?我希望再次进入页面(不通过小程序码)后,this.$router.params.store_id不要再存在了

期望行为
我希望再次进入页面(不通过小程序码)后,this.$router.params.store_id不要再存在了

报错信息

系统信息

  • 操作系统: [e.g. MacOS]
  • Taro 版本 [e.g. v.1.2.21]
  • Node.js 版本 [e.g. v11.4.0]
  • 报错平台 [h5, weapp]

补充信息
[可选]
[根据你的调查研究,出现这个问题的原因可能在哪里?]

@taro-bot
Copy link

taro-bot bot commented Aug 1, 2019

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~

@Chen-jj
Copy link
Contributor

Chen-jj commented Aug 1, 2019

@songming43 "页面跳出再次进入后" 是什么意思,页面A跳页面B,页面B点返回还是再打开新页面A。页面是普通页面还是 Tab 页面,都说详细点。

@Chen-jj Chen-jj self-assigned this Aug 1, 2019
@mingsong2
Copy link
Author

mingsong2 commented Aug 1, 2019

@songming43 "页面跳出再次进入后" 是什么意思,页面A跳页面B,页面B点返回还是再打开新页面A。页面是普通页面还是 Tab 页面,都说详细点。

扫码进入A页面(Tab页面),然后A页面切换到B页面(Tab页面),再次从B页面切换到A页面,this.$router.params中的参数依然在 @Chen-jj

@Chen-jj
Copy link
Contributor

Chen-jj commented Aug 1, 2019

@songming43 那肯定啊,B 回 A,A 页面对象都没有销毁,一直存在

@mingsong2
Copy link
Author

@songming43 那肯定啊,B 回 A,A 页面对象都没有销毁,一直存在

@Chen-jj 怎么清空这个this.$router.params呢?我现在希望,仅在扫小程序码进入A页面的时候this.$router.params中的值存在,从A页面切换到B,再从B切换到A的时候this.$router.params被清空

@Chen-jj
Copy link
Contributor

Chen-jj commented Aug 1, 2019

@songming43 你 didmount 挂 this 上,之后想怎么做都可以。

@mingsong2
Copy link
Author

@songming43 你 didmount 挂 this 上,之后想怎么做都可以。

@Chen-jj 怎么挂呢?

    this.componentDidMount = componentDidMount(){
          this.$router.params = {};
    }

这样吗?

@Chen-jj
Copy link
Contributor

Chen-jj commented Aug 1, 2019

@songming43

componentDidMount () {
  this.parmas = this.$router.params
}

componentDidShow () {
  this.params = {}
}

@Chen-jj Chen-jj added answered question Further information is requested labels Aug 1, 2019
@taro-bot taro-bot bot added the to be closed label Aug 1, 2019
@taro-bot
Copy link

taro-bot bot commented Aug 1, 2019

Hello~

您的问题楼上已经有了确切的回答,如果没有更多的问题这个 issue 将在 15 天后被自动关闭。

如果您在这 15 天中更新更多信息自动关闭的流程会自动取消,如有其他问题也可以发起新的 Issue。

Good luck and happy coding~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants