gpt4 book ai didi

html - 如何在您的网站上使用 dartscript

转载 作者:行者123 更新时间:2023-12-03 03:43:38 25 4
gpt4 key购买 nike

你好,我刚开始学习一些 Dart ,我也是这个论坛的新手,

我用 webstorm 创建了 ubersimple webapp,并编写了一个非常简单的 dart 脚本和一个 html 文档。

我的 html 文档的负责人:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="scaffolded-by" content="https://github.com/google/stagehand">
<title>Das bist du!</title>
<script defer src="http://das-bist-du.com/main.dart" type="application/dart"></script>
<script defer src="http://das-bist-du.com/packages/browser/dart.js"> </script>
</head>

<body>
</body>
</html>

Dart 代码:
import 'dart:html';
import 'dart:math';

ButtonElement rndButton;
ImageElement rndImage;
var images;
var rng;

void main() {
rndButton = querySelector('#rndButton');
rndImage = querySelector('#imgScreen');

images = ['http://das-bist-du.com/onewebmedia/anN0MBo_700b.jpg', 'http://das-bist-du.com/onewebmedia/du1.jpg', 'http://das-bist-du.com/onewebmedia/du2.jpg', 'http://das-bist-du.com/onewebmedia/du3.jpg', 'http://das-bist-du.com/onewebmedia/du3.jpg', 'http://das-bist-du.com/onewebmedia/du4.jpg', 'http://das-bist-du.com/onewebmedia/du5.jpg', 'http://das-bist-du.com/onewebmedia/du6.jpg'];
rndButton.onClick.listen(pickYou);
}
void pickYou (Event e) {
rng = new Random();
setYou(rng.nextInt((images.length)));
}

void setYou (var rnd) {
print(images[rnd].toString());
rndImage.src = (images[rnd].toString());
}

我知道代码并不漂亮,我只是在测试。 :)

现在我想在网站上同时使用两者,我将 html 页面的代码和 dart.js 上传到网站,并将 src 放在 html 脚本标签中。

在使用 Chromium 在 Webstorm 中进行测试时,它可以工作。
但该脚本不在网站上运行。如何在网站上在线使用 Dart ?

提前致谢

最佳答案

Dart 不直接在任何浏览器中运行,除了 Dartium(基于 Chomium 的 Dart 开发浏览器,包含 Dart VM)。

当你运行 pub build在您的项目目录(pubspec.yaml 所在的位置)中,您将在 build 中获得输出子目录,可以上传到网络服务器供公众使用。

pub build 时,还有一个转换器可以优化脚本标签。正在运行。 https://pub.dartlang.org/packages/dart_to_js_script_rewriter

关于html - 如何在您的网站上使用 dartscript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36979751/

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