Last active
January 16, 2016 04:04
-
-
Save daog1/7e9b7c86ab447a7a58f6 to your computer and use it in GitHub Desktop.
自定义web组件
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Title</title> | |
<script src="/static/dist/webcomponents.js"></script> | |
<script src="/static/dist/react.js"></script> | |
<script src="/static/dist/react-dom.js"></script> | |
<script src="/static/dist/react-with-addons.js"></script> | |
<script src="/static/dist/reactive-elements.js"></script> | |
<script src="/static/dist/browser.min.js"></script> | |
</head> | |
<script type="text/babel"> | |
var MyComponent = React.createClass({ | |
handleClick: function() { | |
//console.log("test"); | |
this.refs.myTextInput.focus(); | |
}, | |
render: function() { | |
return ( | |
<div> | |
<input type="text" ref="myTextInput" /> | |
<input type="button" value="Focus the text input" onClick={this.handleClick} /> | |
</div> | |
); | |
} | |
}); | |
/* | |
var proto2 = Object.create(HTMLElement.prototype, { | |
handleClick: function() { | |
console.log("test"); | |
}, | |
createdCallback: { | |
value: function() { | |
var mountPoint = document.createElement ('div'); | |
this.createShadowRoot().appendChild(mountPoint); | |
//var name = this.getAttribute('name'); | |
//var url = 'https://www.google.com/search?q=' + encodeURIComponent(name); | |
console.log("hello"); | |
ReactDOM.render(<MyComponent/>, mountPoint); | |
} | |
} | |
});*/ | |
document.registerReact('yx-input', MyComponent); | |
</script> | |
<body> | |
<p>dddd</p> | |
<div id="container"></div> | |
<yx-input /> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/webcomponents/webcomponentsjs