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

在特定情况下created内的数据操作不生效 #735

Closed
asd123freedom opened this issue Nov 28, 2022 · 2 comments
Closed

在特定情况下created内的数据操作不生效 #735

asd123freedom opened this issue Nov 28, 2022 · 2 comments

Comments

@asd123freedom
Copy link

场景:根组件的根元素是另一个有slot的组件,在此slot里面嵌入另一个组件。
操作:在生命周期函数尝试更新数据。
结论:this.data.set写在created无效,在inited和attached里面都有效

复现demo地址:https://codesandbox.io/s/jovial-gianmarco-ur0tty

示例代码截图:

97cfba73915adae2d9b3406be26f1c8f

@zhengmz
Copy link
Contributor

zhengmz commented Dec 5, 2022

这个可能是因为 rawData 是一个 Object,所以 created 中应该使用以下语句

this.data.set("rawData.title", "created title");

@errorrik
Copy link
Contributor

errorrik commented Jan 7, 2023

created 意味着在创建过程中,语义是创建视图节点了。这时候数据变化,需要对生成的视图结构重新生成,是不合理的,会带来其他问题。

建议在 inited 中初始化数据。

其实,Page 组件不是用 c-person,而是用 div 当 root element,可以解决这个问题。这个涉及到视图初始化过程对于不同节点的创建顺序,不展开了。

还是建议在 inited 中初始化数据。

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