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

当页面中同时使用router和store时,vue对象无法获取到ctx.render中设置的参数。 #105

Closed
lingang001 opened this issue Dec 7, 2018 · 2 comments

Comments

@lingang001
Copy link

index.js (controller)

...
// 页面渲染时使用的参数
const params = {
  logo: 'test',
  //some....
};
await this.ctx.render('admin/index.js',  params);
...

index.vue(admin/index.js)

...
export default { 
  router, 
  store, 
  created() {
    // 获取到的值为undefined
    console.log(this.logo)
  },
}
...

当页面中同时使用router和store时,vue对象无法获取到ctx.render中设置的参数。

按照上面的代码,我想在vue中使用this.logo的参数。实际情况是this.logo的参数在浏览器中打印为undefined。

我的解决方案是将router写在另外一个component中,然后再引用。但是,之前版本(easywebpack-vue 3.x)不存在这个问题。

目前使用的版本依赖

  "dependencies": {
    // some...
    "egg": "^2.1.0",
    "egg-view-vue-ssr": "^3.0.5",
    "vue": "^2.5.0",
    "vue-router": "^3.0.1",
    "vuex": "^3.0.1",
    "vuex-router-sync": "^5.0.0",
  },
  "devDependencies": {
    // some...
    "easywebpack-cli": "^4.0.0",
    "easywebpack-vue": "^4.2.0",
    "egg-logview": "^1.0.0",
    "egg-webpack": "^4.4.1",
    "egg-webpack-vue": "^2.0.0",
  }
@wangshun23
Copy link

this.$store.state.logo 试试

@hubcarl
Copy link
Collaborator

hubcarl commented Aug 8, 2019

#120

@hubcarl hubcarl closed this as completed Aug 8, 2019
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