Skip to content

Instantly share code, notes, and snippets.

@daog1
Last active January 16, 2016 04:04
Show Gist options
  • Save daog1/7e9b7c86ab447a7a58f6 to your computer and use it in GitHub Desktop.
Save daog1/7e9b7c86ab447a7a58f6 to your computer and use it in GitHub Desktop.
自定义web组件
<!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>
@daog1
Copy link
Author

daog1 commented Jan 16, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment