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.$preload 函数,跳转后报错。 #3694

Closed
wakaka378 opened this issue Jul 5, 2019 · 4 comments
Closed

小程序使用 this.$preload 函数,跳转后报错。 #3694

wakaka378 opened this issue Jul 5, 2019 · 4 comments
Assignees

Comments

@wakaka378
Copy link

问题描述
小程序在页面跳转传参时候,通过this.$preload 函数传递参数。在跳转页面通过this.$router.preload来接受,能接收到参数。但是小程序一直报错说, Cannot read property 'goodsId' of undefined 我接受的参数没有定义,让我给页面提供初始 state 以提高初次渲染性能!然后我也在state里面定义了goodsId,他还是报错。

复现步骤
在credit页面点击跳转传递参数

this.$preload({
        goodsId: id,
        money: money,
        version: version
      })

跳转页面接受参数 userpost

<Info goodsId={this.$router.params.goodsId || this.$router.preload.goodsId } money={this.$router.params.money || this.$router.preload.money } version={this.$router.params.version || this.$router.preload.version} remainNum={this.state.recommend.remainNum} />

// 一种是h5路由跳转接受参数  数据是要传递给Info子组件

然后就开始报错

[Taro warn] 请给页面提供初始 `state` 以提高初次渲染性能!
console.warn @ VM277:1
createComponent @ index.js:1934
(anonymous) @ userpost.js:154
require @ WAService.js:1
(anonymous) @ VM395:176
scriptLoaded @ appservice?t=1562316558992:2173
script.onload @ appservice?t=1562316558992:2185
VM277:1 TypeError: Cannot read property 'goodsId' of undefined
    at Connect._createData (userpost.js:112)
    at Object.createComponent (index.js:1931)
    at userpost.js:154
    at require (WAService.js:1)
    at <anonymous>:176:7
    at HTMLScriptElement.scriptLoaded (appservice?t=1562316558992:2173)
    at HTMLScriptElement.script.onload (appservice?t=1562316558992:2185)

我在userpost页面的state里面定义数据

state = {
    banner: [{ imgurl: 'banner01.jpg' }],
    recommend: {
      recommendNum: 0,
      selectNum: 0,
      remainNum: 0
    },
    goodsId: null,
    version: null,
    money: null,
    remainNum: null
  }

期望行为
文档说,这种方式可以提高小程序的性能,可是在参数接受的时候就出来问题。

报错信息
image

系统信息
� Taro v1.3.4

Taro CLI 1.3.4 environment info:
System:
OS: Windows 7
Binaries:
Node: 10.16.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.16.0 - ~\AppData\Roaming\npm\yarn.CMD
npm: 6.9.0 - C:\Program Files\nodejs\npm.CMD

@taro-bot
Copy link

taro-bot bot commented Jul 5, 2019

欢迎提交 Issue~

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

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

Good luck and happy coding~

@Garfield550
Copy link
Collaborator

既然是 Id 了,就不能定义一个 0 或者 -1 试试。

@wakaka378
Copy link
Author

既然是 Id 了,就不能定义一个 0 或者 -1 试试。
没用,给了程序就不走

@wakaka378
Copy link
Author

数据处理问题

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

No branches or pull requests

3 participants