编译和安装的标签似乎没有更新

A compiled and mounted tag doesn't seem to update

在编译并安装一个读取从其父级传下来的选项 属性 的标签后,当传下来的选项更新时,我无法让子级读取 属性 进行更新。

查看问题演示 运行:

git clone https://github.com/shouston3/learn-riot.git && cd learn-riot/demo-problem

npm i && npm start

visit http://localhost:3333

当您递增计数器时,未编译的计数器将更新,

但是编译好的不会

我怎样才能让它更新?

在此先感谢您的帮助

我假设你想增加 parent 和 child 标签,我简化了你的代码。我删除了 var self=this,在这种情况下不需要,并将此分配 self.opts.count = ++self.opts.count; 更改为 this.count = ++this.count

问题是您试图将数据分配给 opts,但它不是这样工作的。要将数据传递给 children,您只需传递标签 <count count={this.count}></count> 中的参数(最好为标签和变量使用不同的名称)

这是代码

  <demo>
    <button onclick={increment}>increment</button>

    <h1>Uncompiled count: {this.count}</h1>

    <count count={this.count}></count>

    this.count = 0;

    increment () {
      this.count = ++this.count;
      console.log('count: ', this.count);
      this.update();
    }

  </demo>

这是例子 https://jsfiddle.net/vitomd/mjqa2d5j/4/