您好,我也开始在该论坛上学习飞镖和即时消息,
我用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>
飞镖代码:
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中进行测试时,它可以工作。但是脚本不会在网站上运行。如何在网站上在线使用飞镖?
提前致谢
除了Dartium(包括Dart VM的基于Chomium的Dart开发浏览器)外,Dart都不能直接在任何浏览器中运行。
当您pub build
在项目目录(pubspec.yaml
是)中运行时,您会在子目录中获得输出,该输出build
可以上载到Web服务器以供公共使用。
还有一个可用的转换器,可在pub build
运行时优化脚本标签。https://pub.dartlang.org/packages/dart_to_js_script_rewriter
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句