成都网站建设设计

将想法与焦点和您一起共享

webpack使用原生js和react分别搭建项目

  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:

    岐山网站制作公司哪家好,找创新互联建站!从网页设计、网站建设、微信开发、APP开发、响应式网站开发等网站项目制作,到程序开发,运营维护。创新互联建站从2013年创立到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选创新互联建站

    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:

    
    
    
        hello
    
    
        
    
    

    g. 效果:
    webpack使用原生js和react分别搭建项目

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

    b. table.jsx:

    var React = require('react')
    var CreateReactClass = require('create-react-class')
    var table = CreateReactClass({
    render:function(){
        return(
                
    head
    body
    ) } }) module.exports = table

    c. foot.jsx:

    var React = require('react')
    var CreateReactClass = require('create-react-class')
    var foot = CreateReactClass({
    render:function(){
        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 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(
                
    ) } }) ReactDom.render( , document.getElementById('app') )

    f. index.html:

    
    
    
        hello
    
    
        

    g. 效果:
    webpack使用原生js和react分别搭建项目


    新闻名称:webpack使用原生js和react分别搭建项目
    转载来源:http://chengdu.cdxwcx.cn/article/phohip.html