webpack使用原生js和react分別搭建項(xiàng)目

  1. 原生js:
    a. head.jsx:
    function head(){
    var head = document.createElement('div')
    head.setAttribute('class','head')
    head.innerHTML = "head"
    return head
    }
    module.exports = head

    b. table.jsx:

    岐山網(wǎng)站制作公司哪家好,找創(chuàng)新互聯(lián)建站!從網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、響應(yīng)式網(wǎng)站開發(fā)等網(wǎng)站項(xiàng)目制作,到程序開發(fā),運(yùn)營維護(hù)。創(chuàng)新互聯(lián)建站從2013年創(chuàng)立到現(xiàn)在10年的時(shí)間,我們擁有了豐富的建站經(jīng)驗(yàn)和運(yùn)維經(jīng)驗(yàn),來保證我們的工作的順利進(jìn)行。專注于網(wǎng)站建設(shè)就選創(chuàng)新互聯(lián)建站。

    function table(){
    var table = document.createElement('table')
    table.setAttribute('class','table')
    var thead = document.createElement('thead')
    var tbody = document.createElement('tbody')
    var tdh = document.createElement('td')
    var tdb = document.createElement('td')
    var tnh = document.createTextNode('title')
    var tnb = document.createTextNode('body')
    tdh.appendChild(tnh)
    tdb.appendChild(tnb)
    thead.appendChild(tdh)
    tbody.appendChild(tdb)
    table.appendChild(thead)
    table.appendChild(tbody)
    return table
    }
    module.exports = table

    c. foot.jsx:

    function foot(){
    var foot = document.createElement('div')
    foot.setAttribute('class','foot')
    foot.innerHTML = "foot"
    return foot
    }
    module.exports = foot

    d. test.less:

    .color(@color;@background){
    color:@color;
    background:@background;
    }
    .table(){
    border-collapse:collapse;
    border:1px solid black;
    padding:1vh 1vw;
    }
    .head{
    .color(red,yellow);
    }
    .table{
    .table();
    }
    .foot{
    .color(white,black);
    }

    e. index.js:

    var head = require('./static/jsx/head.jsx')
    var table = require('./static/jsx/table.jsx')
    var foot = require('./static/jsx/foot.jsx')
    require('./static/less/test.less')
    document.body.appendChild(head())
    document.body.appendChild(table())
    document.body.appendChild(foot())

    f. index.html:

    <!doctype html>
    <html>
    <head>
        <title>hello</title>
    </head>
    <body>
        <script src="bundle.js"></script>
    </body>
    </html>

    g. 效果:
    webpack使用原生js和react分別搭建項(xiàng)目

  2. react:
    a. head.jsx:
    var React = require('react')
    var CreateReactClass = require('create-react-class')
    var head = CreateReactClass({
    render:function(){
        return(
                <div class="head">head</div>
            )
    }
    })
    module.exports = head

    b. table.jsx:

    var React = require('react')
    var CreateReactClass = require('create-react-class')
    var table = CreateReactClass({
    render:function(){
        return(
                <table class="table">
                    <thead>
                        <td>head</td>
                    </thead>
                    <tbody>
                        <td>body</td>
                    </tbody>
                </table>
            )
    }
    })
    module.exports = table

    c. foot.jsx:

    var React = require('react')
    var CreateReactClass = require('create-react-class')
    var foot = CreateReactClass({
    render:function(){
        return(
                <div class="foot">foot</div>
            )
    }
    })
    module.exports = foot

    d. test.less:

    .color(@color;@background){
    color:@color;
    background:@background;
    }
    .table(){
    border-collapse:collapse;
    border:1px solid black;
    padding:1vh 1vw;
    }
    .head{
    .color(red,yellow);
    }
    .table{
    .table();
    }
    .foot{
    .color(white,black);
    }

    e. index.js:

    var React = require('react')
    var ReactDom = require('react-dom')
    var CreateReactClass = require('create-react-class')
    var Head = require('./static/jsx/head.jsx')
    var Table = require('./static/jsx/table.jsx')
    var Foot = require('./static/jsx/foot.jsx')
    require('./static/less/test.less')
    var App = CreateReactClass({
    render:function(){
        return(
                <div>
                    <Head/>
                    <Table/>
                    <Foot/>
                </div>
            )
    }
    })
    ReactDom.render(
        <App/>
        ,
        document.getElementById('app')
    )

    f. index.html:

    <!doctype html>
    <html>
    <head>
        <title>hello</title>
    </head>
    <body>
        <div id="app"></div>
        <script src="bundle.js"></script>
    </body>
    </html>

    g. 效果:
    webpack使用原生js和react分別搭建項(xiàng)目

分享文章:webpack使用原生js和react分別搭建項(xiàng)目
文章地址:http://www.muchs.cn/article8/phohip.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供用戶體驗(yàn)、App設(shè)計(jì)手機(jī)網(wǎng)站建設(shè)、品牌網(wǎng)站制作服務(wù)器托管、搜索引擎優(yōu)化

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)公司