We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
理论上 Component 中应该先初始化 data 中的值,然后在触发 attached() 函数。
在组件完全初始化完毕、进入页面节点树后, attached 生命周期被触发。此时, this.data 已被初始化为组件的当前值。这个生命周期很有用,绝大多数初始化工作可以在这个时机进行。
但是使用了 create.Component 后似乎是先执行 attached(),然后初始化 data.
下面我贴一下我的 Demo
// index/component/index.js import create from '../../omix/create' import store from '../../store.js' create.Component(store,{ /** * 组件的属性列表 */ properties: { }, /** * 组件的初始数据 */ data: { msg: "hello", }, lifetimes: { attached() { this.setData({ msg: 'world' }) console.log("attached:", this.data.msg) }, ready() { console.log("ready:", this.data.msg) } }, /** * 组件的方法列表 */ methods: { }, observers: { msg(val){ console.log("msg observers: ", val) } } })
输出:
msg observers: world index.js:24 attached: world msg observers: hello index.js:27 ready: hello
完整的小程序代码片段:
https://developers.weixin.qq.com/s/Qlghs8mt7FnU
如果直接使用 Component() 函数构造组件则输出如下所示,符合预期。
msg observers: world index.js:24 attached: world index.js:27 ready: world
The text was updated successfully, but these errors were encountered:
遇到同样的问题了
Sorry, something went wrong.
我们自己魔改了一下可以用了 我有点诧异..... 官方出的竟然会搞错的生命周期
No branches or pull requests
理论上 Component 中应该先初始化 data 中的值,然后在触发 attached() 函数。
但是使用了 create.Component 后似乎是先执行 attached(),然后初始化 data.
下面我贴一下我的 Demo
输出:
完整的小程序代码片段:
如果直接使用 Component() 函数构造组件则输出如下所示,符合预期。
The text was updated successfully, but these errors were encountered: