gpt4 book ai didi

javascript - Meteor HTML 未呈现

转载 作者:行者123 更新时间:2023-11-28 18:18:00 25 4
gpt4 key购买 nike

我的 meteor 项目有以下结构

client/
src/
test1.js
test2.js
main.css
main.js
main.html
server/

main.html例如:

<head>
<title>meteorTest</title>
</head>

<body>
<h1>Welcome to Meteor!</h1>

{{> hello}}

</body>

<template name="hello">
<canvas id="canvas"></canvas>
</template>

但是输出为空,这意味着 <h1>也不是 canvas显示在 DOM 中。当我删除src时-文件夹,<h1>canvas被渲染。

可能是什么问题?

最佳答案

我会这样构建你的文件:

 client/
src/
test1.js // Since it seems working when you remove them,
test2.js // somethings seems wrong with their code. Maybe post it?
helpers/
body.js
templates/
body.html
hello.html
main.css
main.js
main.html
server/

使用 body.html:

<body>
<h1>Welcome to Meteor!</h1>
{{> hello}}
</body>

使用 hello.html:

<template name="hello">
<canvas id="canvas"></canvas>
</template>

然后你的javascript代码在body.js中:

import '../templates/body.html';
import '../templates/hello.html';

//All your JS code here or imports of other .js

然后在您的客户端根文件夹中:

main.html:

<head>
<title>meteorTest</title>
</head>

最后,您需要将所有内容放入 main.js 文件中:

import './helpers/body.js'

通常,在项目的根目录中有一个单独的“导入”文件夹是有意义的。您可以通过这种方式声明服务器端和客户端代码,并确定在服务器/客户端上导入哪些代码。由于您的项目看起来更像是 meteor 测试,并且您没有服务器代码,但上面的结构现在应该可以做到这一点。

关于javascript - Meteor HTML 未呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40508251/

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