【发布时间】:2015-04-25 00:08:30
【问题描述】:
我正在尝试使用 React 创建 Aurelia 自定义元素,通过在 Aurelia Q & A 上遵循此示例并发生以下异常:
Potentially unhandled rejection [1] TypeError: Cannot read property 'render' of undefined
我做错了什么?这是我的测试代码:
test.html
<import from="./myelement"></import>
<my-element foo.bind="Value"></my-element>
myelement.html
<template>
<input type="text" placeholder="user">
</template>
myelement.js
import {Behavior} from 'aurelia-framework';
import {React} from 'aurelia-framework';
export class MyElement {
static metadata(){
return Behavior
.customElement('my-element')
.withProperty('foo')
.noView();
}
static inject() {
return [Element];
}
constructor(element) {
this.element = element;
console.log('this:', this);
console.log('element:', element);
}
bind() {
// React.render(<MyReactElement foo={this.foo} />, this.element);
React.render(React.createElement(MyReactElement, { foo: this.foo }), this.element);
}
fooChanged() {
this.bind();
}
}
【问题讨论】:
-
我想
import {React} from 'aurelia-framework';实际上应该是:import {React} from 'react'; -
对,
import React from 'react'其实 -
问题解决了吗?
-
好的,谢谢。阅读我认为 react 内部使用的博客,不是这种情况。
标签: javascript reactjs ecmascript-6 aurelia