簡體   English   中英

使用自定義屬性創建react元素

[英]Creating react element with custom attributes

我是新來的人,第一個應用程序。 我正在嘗試創建具有數據屬性的自定義元素。 目前我正在用純ES5編寫,所以還沒有JSX,Babel或ES6。 那將是下一個。

var myEl = React.createClass({
    displayName : 'elCont',
    render: function() {
        return(
            React.createElement('My-Shiney-Element', {
                data: data,
                conf: conf
            })
         );
     )}


var data = [1,2,3,4,5,6];
var conf = {"show": true};

我可以在html <my-shiney-element><\\my-shiney-element>看到屬性,但是沒有?

您可以使用

<my-shiney-element foo="bla"><\my-shiney-element> 

在您的代碼中,您可以使用“ this.props.foo”訪問“ foo”

https://facebook.github.io/react/docs/transferring-props.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM