React組件-mixin

來源:互聯網
上載者:User

標籤:

一、組件

二、代碼

 1 <!DOCTYPE html> 2 <html lang="zh-cn"> 3 <head> 4     <meta charset="UTF-8"> 5     <title>Mixin</title> 6 </head> 7 <body> 8     <script src="./react-0.13.2/react-0.13.2/build/react-with-addons.js"></script> 9     <script src="./react-0.13.2/react-0.13.2/build/JSXTransformer.js"></script>10     <script type="text/jsx">11         // var BindingExample = React.createClass({12         //     getInitialState: function() {13         //         return {14         //             text: ‘‘15         //         }16         //     },17         //     handleChange: function(event) {18         //         this.setState({text: event.target.value})19         //     },20         //     render: function() {21         //         return <div>22         //             <input type="text" placeholder="請輸入內容" onChange={this.handleChange} />23         //             <p>{this.state.text}</p>24         //         </div>25         //     }26         // })27         var BindingMixin = {28             handleChange: function(key) {29                 var that = this30                 var newState = {}31                 return function(event) {32                     33                     newState[key] = event.target.value34                     that.setState(newState)35                 }36             }37         }38         var BindingExample = React.createClass({39             mixins: [React.addons.LinkedStateMixin],40             getInitialState: function() {41                 return {42                     text: ‘‘,43                     comment: ‘‘,44                 }45             },46             render: function() {47                 return <div>48                     <input type="text" placeholder="請輸入內容" valueLink={this.linkState(‘text‘)} />49                     <textarea valueLink={this.linkState(‘comment‘)}></textarea>50                     <p>{this.state.text}</p>51                     <p>{this.state.comment}</p>52                 </div>53             }54         })55         React.render(<BindingExample></BindingExample>, document.body);56     </script>57 </body>58 </html>

 

React組件-mixin

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.