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

address组件异步加载数据 #26

Closed
sandysong opened this issue Mar 10, 2016 · 12 comments
Closed

address组件异步加载数据 #26

sandysong opened this issue Mar 10, 2016 · 12 comments
Milestone

Comments

@sandysong
Copy link

希望address组件支持从后台异步加载数据,可以将list作为组件参数传给组件

@airyland airyland added this to the 0.1.0 milestone Mar 10, 2016
@airyland
Copy link
Owner

剥离数据在开发计划中,但是要求参数格式和目前的统一。

@sandysong
Copy link
Author

试了一下,虽然可以通过list传数据进去,但是父组件是异步从server端取list的,初始化的时候会报错:
Uncaught TypeError: Cannot read property 'value' of undefined
Uncaught TypeError: Cannot read property 'name' of undefined

@airyland
Copy link
Owner

传进去是数据还是空的?

@sandysong
Copy link
Author

我是在父组件的created钩子里异步从server端加载数据,然后设置到父组件的data.list里,address组件的list和父组件data.list绑定。这样用对么?

@airyland
Copy link
Owner

这样的话,address组件一开始会没有数据,初始化失败。如果你用vue-router的话,可以使用 data 钩子来在compile组件前进行数据获取

http://vuejs.github.io/vue-router/zh-cn/pipeline/data.html

我也在考虑支持异步设置 list 和 value,但是可能出现用户操作时list还没有获取成功的情况

@sandysong
Copy link
Author

data钩子估计也不行,异步请求最终都一样

@airyland
Copy link
Owner

这样子能保证在组件初始化前数据已经获取到了。

@sandysong
Copy link
Author

我知道了,我尝试一下

@sandysong
Copy link
Author

试了一下,貌似在data钩子调用前就js报错了

@airyland
Copy link
Owner

添加 waitForData: true 呢

@sandysong
Copy link
Author

异步取数据写在data钩子里,然后为组件加上v-if="!$loadingRouteData"解决了

@airyland
Copy link
Owner

@sandysong 👍 这种思路不错。

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

No branches or pull requests

2 participants