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

请问一下数据加载的问题 #5

Open
Rubyguo opened this issue May 22, 2018 · 4 comments
Open

请问一下数据加载的问题 #5

Rubyguo opened this issue May 22, 2018 · 4 comments

Comments

@Rubyguo
Copy link

Rubyguo commented May 22, 2018

我在methods里定义了方法dispatch了一个action,在action里请求api,并拿到返回的数据,然后commit给mutation里的方法,并更新state,到这里数据都是正常的。但是刷新页面时数据加载不出来。用的也是computed: {
...mapState({
videos: 'videos'
})
},
请问是数据没有加载完就渲染了页面的原因吗

@xxxgitone
Copy link
Owner

@Rubyguo vuex管理状态是没有持久化的,意味着你刷新后,所有状态都会回到初始化时候的样子.如果你想要保存当前面页面状态,你可以重新再进行一次请求.

@Rubyguo
Copy link
Author

Rubyguo commented May 23, 2018

我之前的表述有一些问题:情况是这样,我在父组件A中发送api请求,返回的数据赋值给$store.state.a,$store.state.b,然后在父组件A中和子组件B中都采用computed: {...mapState({})}的方式分别把a和b映射到本地变量,在初始化页面的时候,A中的数据正常显示而B中数据显示不出来。但是再局部刷新一次后,B中的数据就能显示了,请问这是什么原因造成的

@xxxgitone
Copy link
Owner

@Rubyguo 方便的话可以提供相关的代码.

@Rubyguo
Copy link
Author

Rubyguo commented May 26, 2018

找到原因了,我在子组件里用的echarts,没办法实现数据绑定,每次刷新ehcarts里的图必须重新设置option里的数据。我用prop让子组件直接继承父组件数据,在watch里监听,一旦数据改变就用函数刷新option里的数据,这样实现数据绑定

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

2 participants