【问题标题】:Why doesn't this Web-UI code work?为什么这个 Web-UI 代码不起作用?
【发布时间】:2013-04-06 11:16:09
【问题描述】:

我使用 web-ui 创建了一个新的网络应用程序。所有软件包似乎都已正确安装。我运行了生成的“点击计数器”示例,但它没有出现。我去了Web-UI文章并粘贴了这段代码:

<!DOCTYPE html>
<!--
Copyright (c) 2012, the Dart project authors.  Please see the AUTHORS file
for details. All rights reserved. Use of this source code is governed by a
BSD-style license that can be found in the LICENSE file.
-->
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

</head>
<body>
  <element name="x-click-counter" constructor="CounterComponent" extends="div">
    <template>
      <button on-click="increment()">Click me</button>
      <span>(click count: {{count}})</span>
    </template>
    <script type="application/dart">
      import 'package:web_ui/web_ui.dart';

      class CounterComponent extends WebComponent {
        int count = 0;
        void increment() { count++; }
      }
    </script>
  </element>
  <div class="well">
    <div is="x-click-counter" count="{{myNumber}}"></div>
    <div is="x-click-counter" count="{{5}}"></div>
  </div>
  <script type="application/dart">
    int myNumber = 12;
    main(){}
  </script>
</body>
</html>

但这也没有用。代码有问题吗?它已经过时了吗?是否有一些我没有考虑到的依赖项?

【问题讨论】:

    标签: dart dart-webui


    【解决方案1】:

    代码对我来说很好用。

    您是先运行build.dart 吗?您不能直接运行此脚本并使其工作。您应该有一个看起来像这样的顶级build.dart 文件(我假设该文件位于web/ 目录中并称为click_counter.html):

    import 'packages/web_ui/component_build.dart';
    import 'dart:io';
    
    void main() {
      build(new Options().arguments, ['web/click_counter.html']);
    }
    

    当您运行此文件时,将自动为您生成一个out/ 目录。右击out/目录下的click_counter.html文件,运行。它应该可以工作。

    您可以在http://www.dartlang.org/articles/web-ui/tools.html 阅读有关编译过程的更多信息。

    【讨论】:

    • 你是对的。我现在觉得很愚蠢。不过,非常感谢!另一方面,运行过程现在是从 Dart 编辑器中做的一件痛苦的事情。编辑 web/app.html,保存,运行 build.dart,运行 web/out/app.html。返回 web/app.html 进行编辑。我认为这值得一个脚本。
    • 别觉得自己很傻,我们都犯过同样的错误。你说得对:构建过程可以简化。
    猜你喜欢
    • 2018-11-05
    • 2012-02-22
    • 2023-03-03
    • 2017-10-02
    • 2016-07-10
    • 2010-12-14
    • 2017-04-09
    • 2013-01-30
    • 2014-05-23
    相关资源
    最近更新 更多