-
Notifications
You must be signed in to change notification settings - Fork 20
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
initData() 返回非字面量的值(类型为 function)时,没有正确识别 #99
Comments
我发现 initData 返回值只要不是 Literal 就可能有问题,比如下面的代码组件渲染结果预期是 let foo = { bar: {} }
const MyApp = san.defineComponent({
template: '<div>{{foo.bar == bar}}</div>'
});
var instance = new MyApp({
data: {
foo: foo,
bar: foo.bar
}
}); 如果 initData 在编译期 toString() 后 {
foo: { bar: {} },
bar: {}
} 最终会导致渲染成 推论1:DynamicComponent(输入为 ComponentClass 的情况)只能在运行时执行 initData,因为无法得知它的返回值是否是 Literal。 |
@zhuguoxi 这么写的目的是啥,为了满足什么样的应用场景? |
业务代码中 在使用s-is场景中做判断是否有必要渲染组件。 let components = {
'x-label': defineComponent({
template: `<div>x-laber</div>`
})
}
let cmptKeys = ['x-label', 'other'];
module.exports = defineComponent({
components,
template: `
<div s-for="cmptKey in cmptKeys">
<x-cmpt
s-is="comKey"
s-if="components[comKey]"></x-cmpt>
</div>
`,
initData() {
return {
components,
cmptKeys
}
}
}) |
let components = {};
let cmptKeys = [];
let template = '<fragment>';
cmptKeys.forEach(key => {
if (components[key]) {
template += `<div><x-cmpt s-is="${components[key]}" /></div>`;
}
});
template += '</fragment>';
module.exports = defineComponent({
components,
template
}); 组件实例化前就确定的东西,不必等到组件渲染时 |
## [4.6.3](v4.6.2...v4.6.3) (2021-04-14) ### Bug Fixes * initData() 返回值不是字面量时序列化结果不正确的问题, close [#99](#99) ([17c2256](17c2256))
🎉 This issue has been resolved in version 4.6.3 🎉 The release is available on: Your semantic-release bot 📦🚀 |
报错信息:
无输出 html string
The text was updated successfully, but these errors were encountered: