React及npm的使用常見錯誤;新手來着

 /*使用npm常見的報錯處理
    (1)更換npm爲淘寶的源
    npm install -g cnpm --registry=https://registry.npm.taobao.org
    (2)項目運行的時候;8080端口不要被被佔用;因爲一個8080端口只能用於一個地方;
    (3)報錯----ERROR in Entry module not found: Error: Cannot resolve 'file' or 'directory' C:\Users\?
    想要作爲引用關係的js組件文件不要隨便放到一個dist文件裏面;一定要放到component文件夾中;
    (4)在使用Ant Design組件庫的時候
    import { Form, Input, Select, Checkbox, DatePicker, Col, Radio, Button, Modal, message } from 'antd'
    const FormItem = Form.Item
如上面的import裏面並不需要加載Form.Item組件;只需要加載Form即可;
     (5)如果要引入包中的某個文件;可以直接使用相對路徑如
    'antd/dist/antd.css'
     (6) 在主文件main.js中
     App組件用來<Route path="/" component={Sider}>書寫路由;
     Sider組件用來寫Link即鏈接單頁面;並且一般如 Link 組件後面不要加 :nbsp;
    (7)import ReactDOM from 'react-dom'
    (8) 動畫的實現
    第1步:現在文件頭部加入這個  var ReactCSSTransitionGroup =require('react-addons-css-transition-group');
    或  var ReactCSSTransitionGrop=React.addons.ReactCSSTransitionGrop;
    第2步: 在要有動畫的元素中加入此標籤<ReactCSSTransitionGroup transitionName="example">
    transitionName代表動畫的名稱;
    第3步:寫css樣式;
    .example-enter         ---》過程先變成這裏的樣式
    .example-enter-active  ---》最終變到這裏的樣式
    .example-leave         ---》這裏的樣式就是example-enter-active類的樣式;所有這裏一般不需要加樣式;只要加transition即可;設置移除樣式的時間;
    .example-leave-active  ---》移除元素的過程變成這個樣式

    .example-enter {
    opacity: 0;
    font-size: 32px;
    color:red;
    transition: all 1s ease-in;
    }
    .example-enter.example-enter-active {
    opacity: 1;
    font-size: 12px;
    }

    .example-leave {
    transition: all 1s ease-in;
    color:red;
    }
    .example-leave.example-leave-active {
    font-size: 32px;
    opacity: 0;
    color:red;
    }
    (9)獲取數組;操作數組
    var bvaue="sdf";
    1:往數組中添加元素
    (
    1:var newItems = this.state.items;
    newItems.push(bvaue); this.state.item---->[1,2,3,4];;newItems--->arr對象;
    2:var newItems = this.state.items.push(bvaue);----》這裏拿到的是length值;
    )
    2:刪除數組中的元素
    var newItems = this.state.items;
    newItems.splice(i, 1);
    this.setState({items: newItems});
    * */


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章