-
Svelte只会在类似数组的对象上迭代,因为它不可能保证对象的一致行为,它会抛出各种边缘情况,最好在应用程序级别解决。您可以使用标准JavaScript习惯用法来完成这类工作:
{{#each Object.values(info.attributes) as attr}}
<p>{{attr.description}} ...</p>
{{/each}}
<!-- or, if you need the key as well -->
{{#each Object.entries(info.attributes) as [key, value]}}
<p>{{attr.description}} ...</p>
{{/each}}
-
不知道直接的角度转换等价物,但一个简单的i18n解决方案是在
preload
:
preload({ params, query }) {
return fetch(`/i18n/${locale}.json`)
.then(r => r.json())
.then(dict => {
return { dict };
});
}
然后,您可以参考以下内容
{{dict["hello"]}}
在模板中。更复杂的解决方案将只加载当前页面所需的字符串,并将缓存所有内容等,但基本思想是一样的。
-
我想你可以这样做:
// app/client.js (assuming Sapper >= 0.7)
import COMPONENTS from './config/components.json';
window.COMPONENTS = COMPONENTS;
// app/server.js
import COMPONENTS from './config/components.json';
global.COMPONENTS = COMPONENTS;
不过导入并没有那么糟糕!模块的依赖关系最好是明确的。
-
您可以使用
resolve.modules
网页包中的字段配置:
https://webpack.js.org/configuration/resolve/#resolve-modules
-
这将是使用双向绑定的好地方:
{{#each Object.values(info.attributes) as attr}}
<p>{{attr.description}} <input bind:value=organization_name /></p>
{{/each}}
-
是的
params
对象在页面中始终可用(不是嵌套组件,除非您向下传递道具,而是所有顶级组件,如
routes/whatever/[slug].html
)–所以您可以在模板中引用它
{{params.slug}}
,或在生命周期挂钩和方法中
this.get('params').slug
,无论给定组件是否使用
预加载
.