鍍金池/ 問答
憶往昔 回答
  1. 按需引入 iview https://www.iviewui.com/docs/...

  2. 按需引入 echarts https://github.com/ywwhack/ba...

最后建議,把這些需要按需加載的模塊放到統(tǒng)一放到一個文件里,后面好維護(hù)

命于你 回答

目錄結(jié)構(gòu)

|-src
|----actions
|--------user.js
|--------office.js
|--------index.js
|----reducers
|--------user.js
|--------office.js
|--------index.js
|----pages
|--------office.js

Action整合

actions目錄中的index.js作為所有業(yè)務(wù)的集合,集中配置管理.

actions/index.js

import * as officeActions from './office';
import * as userActions from './user';

export default {
    ...officeActions,
    ...userActions,
}

actions/office.js

//這里的方法名稱要全局唯一
export function getOfficeList(){
    return async(dispatch,getState) => {
        let response = await fetch(url);
        //這里的type一定要全局唯一,因?yàn)闋顟B(tài)變一次每個Reducer都會根據(jù)類型比對一遍
        dispatch({type: 'GET_OFFICE_LIST', payLoad: response.json});
    }
}
export function getOfficeInfo(id){
    return async(dispatch,getState) => {
        let response = await fetch(url+'?id='+id);
        //這里的type一定要全局唯一,因?yàn)闋顟B(tài)變一次每個Reducer都會根據(jù)類型比對一遍
        dispatch({type: 'GET_OFFICE_DETAIL', payLoad: response.json});
    }
}

actions/user.js

//這里的方法名稱要全局唯一
export function getUserList(){
    return async(dispatch,getState) => {
        let response = await fetch(url);
        //這里的type一定要全局唯一,因?yàn)闋顟B(tài)變一次每個Reducer都會根據(jù)類型比對一遍
        dispatch({type: 'GET_USER_LIST', payLoad: response.json});
    }
}

Reducer整合

Reducer目錄中的index.js 所有子狀態(tài)的集合,集中配置管理.

reducers/index.js

import {combineReducers} from 'redux';

import officeReducer from './office';
import userReducer from './user';

const appReducer = combineReducers({
    office: officeReducer,
    user: userReducer,
});
export default appReducer;

reducers/office.js

//初始化狀態(tài)
let initialState = {
    officeList: [],
    officeInfo: {
        "id": "",
        "parent_id": "",
        "parent_ids": "",
        "name": "",
    },
};
const office = (state = initialState, action) => {
    switch (action.type) {
        //處理 類型為 GET_OFFICE_LIST 結(jié)果數(shù)據(jù)
        case 'GET_OFFICE_LIST':
            return Object.assign({}, state, {
                officeList: action.payLoad.data
            });
        //處理 類型為 GET_OFFICE_DETAIL 結(jié)果數(shù)據(jù)
        case 'GET_OFFICE_DETAIL':
            return Object.assign({}, state, {
                officeInfo: action.payLoad.data
            });
        default:
        //如果類型為匹配到 返回當(dāng)前state
            return state;
    }
};
export default office

最終使用

pages/office.js

import React, {Component} from 'react'
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';

//以antd為例
import {Table, Tree, Row, Col, Card, Button, Spin, Modal,Icon} from 'antd';
//引入Action集合,因?yàn)楹苡锌赡苣硞€頁面 需要調(diào)用多個子action
import Actions from '../actions';

class office extends Component {
    //生命周期此次不討論
    componentDidMount() {
        //請求機(jī)構(gòu) 數(shù)據(jù)
        this.props.action.getOfficeList();
  }

    handleOnRowClick = (officeId)=>{
        //點(diǎn)擊行 獲取結(jié)構(gòu)詳情數(shù)據(jù)
        this.props.action.getOfficeInfo(officeId);
    }
    
    render() {
        <div className="tableDistance">
        <Table rowSelection={rowSelection} columns={columns}
               dataSource={this.props.office.officeList}//綁定機(jī)構(gòu)數(shù)據(jù)并展現(xiàn)
               bordered size="middle"
               pagination={false} onRowClick={this.handleOnRowClick}
        />
    </div>
    }

}
//我習(xí)慣叫訂閱-訂閱Reducer/index.js集合中的需要的狀態(tài),reducer/office在這里進(jìn)行綁定(數(shù)據(jù)結(jié)構(gòu)具體見:initState),reducer/office數(shù)據(jù)變化這里就會變化,這里可以理解為數(shù)據(jù)源
const mapStateToProps = (state) => {
    return {
        office: state.office,
        user:state.user
    }
};
//將引入的Actions綁定,使當(dāng)前展現(xiàn)層具備 請求數(shù)據(jù)的能力,需要什么數(shù)據(jù),就請求對應(yīng)的 方法名(這就是為什么腔調(diào)actions/office.js 中的每個action 名稱一定要全局唯一,還是那句話,這個頁面可能需要多個子action的數(shù)據(jù)能力作為數(shù)據(jù)集中展現(xiàn)的基礎(chǔ))
const mapDispatchToProps = (dispatch) => {
    return {
        action: bindActionCreators(Actions, dispatch)
    }
};
//最重要一步 通過react-redux 提供的 connect函數(shù)將 需要的 Reducer和Actions 綁定至 當(dāng)前頁面
export default connect(mapStateToProps, mapDispatchToProps)(office);

只愛你 回答

下次這種問題嘗試去百度下,很多解決方案的

SimpleDateFormat time=new SimpleDateFormat("yyyy-MM-dd"); 
time.format(new Date());
孤影 回答

只能這樣,java thread的interrupt是交互式的,不存在硬性關(guān)閉的機(jī)制

夢一場 回答

加分號啊。老生常談了。

function test(){
    
}
test.prototype = function(){
    console.log("test_prototype");
}; //這里加分號,否則就連成一條語句執(zhí)行了
(function(){
    console.log("立即執(zhí)行函數(shù)");
})()

// 不加分號,瀏覽器就是這樣認(rèn)為的:

test.prototype = (function(){
    console.log("test_prototype");
})(function(){
    console.log("立即執(zhí)行函數(shù)");
})()

// 也就是這樣的:
f1 = function(){
    console.log("test_prototype");
};
f2 = function(){
    console.log("立即執(zhí)行函數(shù)");
};
test.prototype = f1(f2)()

1.4.0 小程序開始有 WXML節(jié)點(diǎn)信息的API

可以通過這個來進(jìn)行操作。

里面有一個boundingClientRect 不正是可以利用的API?

https://mp.weixin.qq.com/debu...

兔囡囡 回答

PC端的網(wǎng)站頁面,通常來說“不可能”直接轉(zhuǎn)成完美移動端頁面?;蛟S你可以把地址放上來,讓大家給你估個價(jià),“友好”地幫你轉(zhuǎn)成移動端頁面。

過客 回答

before-upload時不是可以獲取file嗎?

beforeAvatarUpload(file) {
console.log(file.name);
}

這個file.name就是文件名,上傳成功后賦值就行了

病癮 回答

在main.js里直接import '../xx.less'
所有的全局樣式都可以在這引入。

爛人 回答

window.locatio.pathname 和 download/template/ab.... 中間加個/

吢涼 回答

react-router@v4.0:

  • React Router被拆分成三個包:react-router,react-router-domreact-router-native,目前網(wǎng)站搭建只需要引入react-router-dom即可;

  • 路由器組件無法接受兩個及以上的子元素;

  • ...

更多改變可以查看官方文檔

正確寫法如下:

    import React from 'react'
    import ReactDOM from 'react-dom';
    import { HashRouter, Route, hashHistory, Switch } from 'react-router-dom'
    
    import About from './Router/About'
    import Repos from './Router/Repos'
    import App from './Router/App'
    
    const SliderComponent = () => (
      <Switch>
        <Route exact path='/' component={App} />
        <Route path="/repos" component={Repos}/>
        <Route path="/about" component={About}/>
      </Switch>
    )
    
    ReactDOM.render((
      <HashRouter history={hashHistory}>
        <SliderComponent />
      </HashRouter>
    ), document.getElementById('app'));
青瓷 回答

var a = [{x: 1},{x:2},{x:3}];

for( var k in a){
    if(a[k].x == 1){
        a[k].x = "a";
    }else if(a[k].x == 2){
        a[k].x = "b";
    }else if(a[k].x == 3){
        a[k].x = "c";
    }
}
console.log(a);



把if替換成switch就好了。。不過你是這個意思嘛?
朕略傻 回答

Promise.all() 并不能解決循環(huán)的問題,一般情況下 .all() 的參數(shù)是 Promise 數(shù)組(暫時不考慮其它類似)。那么,數(shù)組中的每個 Promise 都代表著一個異步操作,Promise.all() 的作用是等待這些異步操作全部執(zhí)行完成,所以實(shí)質(zhì)上并不是 Promise.all() 是并發(fā)的,而是 Promise.all() 等待著一堆并發(fā)執(zhí)行完成。

因此,Promise.all() 并不能解決有序循環(huán)。作為特例,如果 Promise.all() 等待的全都是同步代碼,比如題主示例中雖然用了 .map(),映射結(jié)果卻并不是 Promise 對象,而是同步執(zhí)行(直接返回的 id),這種情況下,實(shí)際是依次執(zhí)行的完了再把結(jié)果放入 .all() 的,所以是同步順序循環(huán)處理的(就是 map 干的事情)。題主的第一段代碼,如果變量名不是 promises,你覺得它跟異步或者 Promise 有任何關(guān)系嗎?

然后當(dāng)然要指出 ajax 調(diào)用時候的一個失誤:{} 中的內(nèi)容應(yīng)該是 ajax 的參數(shù),所以應(yīng)該放在括號中 ({...}) 才對。

由于 promises 變量保存的只是一個同步運(yùn)行的結(jié)果集,所以 Promise.all(promises) 其實(shí)就是對 then() 的回調(diào)直接傳遞的這個結(jié)果集,所以 val 的值實(shí)際就是 [1, 2]。因此下面這個寫法是沒有問題的

$.ajax({
    data: val
});

問題在于下面這里

Promise.all(promises)
    .then(function(val) {
        // 問題在把 ajax 放入 then 回調(diào)中之后
        $.ajax({
            data: val
        });
    })
    .catch(function(err) {
        // ....
    });

這里如果 ajax 發(fā)生錯誤,它不會拋異常,而是等待它自己的 .fail() 處理,因?yàn)闆]有定義,所以就被丟棄了。它并不會傳遞到后面的 .catch() 中,要解決這個問題,可以是得用 ajax 自己的 .fail() 來處理錯誤

Promise.all(promises)
    .then(function(val) {
        // 問題在把 ajax 放入 then 回調(diào)中之后
        $.ajax({ data: val })
            .fail(function(err) {
                // 這里處理錯誤邏輯
            });
    });

也可以是,直接將 ajax 的結(jié)果(thenable)傳遞下去,由 Promise 機(jī)制的 .catch() 來處理

Promise.all(promises)
    .then(function(val) {
        // 問題在把 ajax 放入 then 回調(diào)中之后
        return $.ajax({ data: val });
    })
    .catch(function(err) {
        // 處理錯誤邏輯
    });
悶騷型 回答

state.list可以獲取另一個action的list - -

瘋浪 回答

圖片描述
script: [

// {type: 'text/javascript',innerHtml: ` console.log(1\>0) ` }

]

重點(diǎn)在于 **\** 這個符號 就是回車建上面的那個建,你可以試試看

呆萌傻 回答

看題主的描述,估計(jì)對angular都沒有一個基本的了解,我建議先把a(bǔ)ngular的基礎(chǔ)知識過一下,至于你的問題是很容易解決的,angular是組件化的,就比如你的footer模板已經(jīng)寫好了,你想到處復(fù)用它,那你可以新建一個footer組件,然后把你寫好的模板內(nèi)容拷到tooter組件的模板上去,在根模塊注冊好這個組件,然后在其它的頁面上都可以引用這個組件了

陌南塵 回答

beta版啊,,,試試weex init yourprojectname 或者更新weex-toolkit

扯不斷 回答

cdn 版本的 element-ui 設(shè)置的全局變量是 ELEMENT

externals: {
  'element-ui': 'ELEMENT',
}