gpt4 book ai didi

meteor - Uncaught Error : No Iron. 布局已找到,因此您无法使用 yield

转载 作者:行者123 更新时间:2023-12-04 14:12:30 24 4
gpt4 key购买 nike

使用 Meteor 0.9.3 和 iron:router 1.0.0-pre2,即使安装了 iron:layout,此错误也会显示在控制台上,见下文:

willems-mini:iron willem$ meteor add iron:router@=1.0.0-pre2
added iron:location at version 1.0.0-pre2
added iron:dynamic-template at version 1.0.0-pre2
added iron:router at version 1.0.0-pre2
added iron:layout at version 1.0.0-pre2
added iron:middleware-stack at version 1.0.0-pre2
added iron:url at version 1.0.0-pre2
added iron:controller at version 1.0.0-pre2
added iron:core at version 1.0.0-pre2

iron:router: Routing specifically designed for Meteor

没有其他包,只有meteor 的默认值:
willems-mini:iron willem$ meteor list
autopublish 1.0.0 Publish the entire database to all clients
insecure 1.0.0 Allow all database writes by default
iron:router 1.0.0-pre2 Routing specifically designed for Meteor
meteor-platform 1.1.1 Include a standard set of Meteor packages in your app

我正在尝试运行一个非常简单的应用程序:

1个javascript文件:
Router.route('/', function () {
this.render('home');
});

if (Meteor.isClient) {
Template.home.events({
'click button': function () {
console.log('click!');
}
});
}

和 1 个 html 文件:
<head>
<title>iron router test</title>
</head>

<body>
{{> defaultLayout}}
</body>


<template name="defaultLayout">
<header>
{{> yield "header"}}
</header>

<article>
{{> yield}}
</article>

<footer>
{{> yield "footer"}}
</footer>
</template>


<template name="home">
{{#contentFor "header"}}
<button>click header</button>
{{/contentFor}}

<button>click</button>

{{#contentFor "footer"}}
<button>click footer</button>
{{/contentFor}}
</template>

最佳答案

这不是怎么回事iron:router布局应该可以工作。

摆脱你在 body 中显式包含的布局:

{{! this is WRONG, remove the body tag altogether }}
<body>
{{> defaultLayout}}
</body>

您指定 layoutTemplate 的地方在 RouteController :
Router.route('/', function () {
this.render('home');
},{
layoutTemplate:"defaultLayout"
});

明确声明您的 RouteController s 通常是一种更好的设计模式。
lib/router.js
Router.route("/",{
// give the route a name so it figures out itself to use :
// - HomeController
// - a template name "home"
name:"home"
});
lib/controllers/lib/default-layout.js
DefaultLayoutController=RouteController.extend({
layoutTemplate:"defaultLayout"
});
lib/controllers/home.js
HomeController=DefaultLayoutController.extend({
//
});

关于meteor - Uncaught Error : No Iron. 布局已找到,因此您无法使用 yield,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26121109/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com