我的 Meteor 模板是这样排列的:
<template name="main">
{{#if youwashere}}
{{> content}}
{{#else}}
{{> introduction}}
{{/else}}
{{/if}}
</template>
为了确定用户之前是否访问过我的网站,我设置了一个有效的本地存储。然后我尝试这样调用它:
Template.main.helpers({
youwashere(){ return localStorage.getItem('herebefore'); }
});
应该发生的是:如果有一个本地存储项('herebefore')
,那么它将显示名为content
的模板。但如果您的计算机上没有该项目,它会向您显示模板简介
。帮助程序代码最终没有显示,所以我想知道我做错了什么。
编辑:要存储在本地存储上,我使用以下内容:
Template.introduction.events({
'click #button':function(){
localStorage.setItem('herebefore', true);}
});
最佳答案
您的 else
语法有点不对:
<template name="main">
{{#if youwashere}}
{{> content}}
{{else}}
{{> introduction}}
{{/if}}
</template>
关于javascript - 基于localStorage的 meteor 激活模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37285409/