简体   繁体   English

ES6 Class,扩展Ractive

[英]ES6 Class, extending Ractive

I'm using ES6 (via Babel), and looking for the "proper" way to define a Class that extends Ractive (without calling Ractive.extend(...) if possible), since Ractive allows new ( http://docs.ractivejs.org/latest/new-ractive ). 我正在使用ES6(通过Babel),并寻找“正确”的方式来定义扩展Ractive的类Ractive.extend(...)如果可能的话,不调用Ractive.extend(...) ),因为Ractive允许新的( http:// docs) .ractivejs.org / latest / new-ractive )。

Tried the following approach, which almost seems to work: 试过以下几乎看似有效的方法:

class Home extends Ractive {
  constructor() {
    super();
    this.template = "<h1>{{message}}</h1>";
  }

  data() {
    return {
      message: 'This is sample data'
    }
  }

  oninit() {
    console.log('ok');
  }
}

Ractive instance is initialized without error, and oninit is called, however the template seems undefined. Ractive实例初始化没有错误,并且调用oninit ,但模板似乎未定义。

I would like to start using that syntax as well. 我也想开始使用这种语法。 :) :)

But I spent an hour a month ago trying to see if it was hackable, but concluded it's not currently possible due to how some of the component extension works. 但是我一个月前花了一个小时试图查看它是否可以破解,但结论是由于某些组件扩展的工作方式,目前无法实现。 But it's on our radar and should land in a near-future version. 但它在我们的雷达上,并应该在不久的将来版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM