返回的state首次undefined,导致图片第一次404
你state怎么返回的?
...toRefs(state)
Temp workaround:
definePage({
data: {
imgUrl: '...',
},
setup() {
// ...
},
})
OK
@JasKang After taking a look at the source code, there are probably no good solutions for this problem under current architecture. To fix the problem, we need to declare the data options of native Page, but the setup is executed in attached lifetime. And this is a runtime library, we can't do static extracting too.
So I think this should be well documented.
When you need some initial value for a property, you have to manually declare it in data options, otherwise it will be undefined.
Although, wechat miniapp will just ignore undefined value. There are some cases like this issue.
And for your use case, @breezefeng , I recommand using plugins:
createApp({
setup() {
// ...
},
plugins: [
{
name: 'url-prefix',
config: (options) => {
options.data = {
imgUrl: 'xxxxx',
...options.data,
}
},
},
],
})
#14 @a1mersnow 牛的 这个问题目前没有找到好的解决方式,即使添加编译过程 (类似vue 中的 defineProps 宏 ) 也难以处理 hooks(组合式函数)中的类型推断 而如果强制声明初始值就丧失了组合式函数的灵活性。
还需要再进一步讨论