【发布时间】:2018-12-26 09:32:35
【问题描述】:
我正在使用Svelte computed properties example。具体来说,我正在复制示例:
在 Works.html 中
<h1>{hours}</h1>
在我的 JS 中
const workViewer = new WorkViewer({
target: document.querySelector('.works-wrapper'),
data: function(){
return {
time: new Date()
}
},
computed: {
hours: ({ time }) => time.getHours()
}
});
Rollup 编译我的 Svelte 包没有错误:
rollup v0.58.2
bundles public/js/index.js → public\js\bundle.js...
created public\js\bundle.js in 668ms
[2018-07-18 13:39:37] waiting for changes...
但是,在浏览器中,生成的模块缺少所有计算机属性。例如,hours 与
<Works> was created without expected data property 'hours' bundle.js:12488:34
为什么计算属性没有包含在包中?
我怎样才能使它包含在捆绑包中?
【问题讨论】:
-
那是完整的组件源代码吗?
data应该是一个返回对象的函数,而不是对象本身——上面的代码应该是cause a compile error -
@RichHarris 将数据设为对象不会返回编译错误。我已经将
data调整为一个函数,并编辑了上面的代码(仍然导致同样的错误)
标签: javascript computed-properties svelte