按需引入 iview https://www.iviewui.com/docs/...
按需引入 echarts https://github.com/ywwhack/ba...
最后建議,把這些需要按需加載的模塊放到統(tǒng)一放到一個文件里,后面好維護(hù)
|-src
|----actions
|--------user.js
|--------office.js
|--------index.js
|----reducers
|--------user.js
|--------office.js
|--------index.js
|----pages
|--------office.js
actions目錄中的index.js作為所有業(yè)務(wù)的集合,集中配置管理.
import * as officeActions from './office';
import * as userActions from './user';
export default {
...officeActions,
...userActions,
}
//這里的方法名稱要全局唯一
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});
}
}
//這里的方法名稱要全局唯一
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目錄中的index.js 所有子狀態(tài)的集合,集中配置管理.
import {combineReducers} from 'redux';
import officeReducer from './office';
import userReducer from './user';
const appReducer = combineReducers({
office: officeReducer,
user: userReducer,
});
export default appReducer;
//初始化狀態(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
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?
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-dom
和react-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'));
https://jsfiddle.net/yz22v2fg/
a標(biāo)簽?zāi)愣疾粫昧藛???/p>
scrollHeight
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',
}
北大青鳥APTECH成立于1999年。依托北京大學(xué)優(yōu)質(zhì)雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國IT技能型緊缺人才,是大數(shù)據(jù)專業(yè)的國家
北大青鳥中博軟件學(xué)院創(chuàng)立于2003年,作為華東區(qū)著名互聯(lián)網(wǎng)學(xué)院和江蘇省首批服務(wù)外包人才培訓(xùn)基地,中博成功培育了近30000名軟件工程師走向高薪崗位,合作企業(yè)超4
中公教育集團(tuán)創(chuàng)建于1999年,經(jīng)過二十年潛心發(fā)展,已由一家北大畢業(yè)生自主創(chuàng)業(yè)的信息技術(shù)與教育服務(wù)機(jī)構(gòu),發(fā)展為教育服務(wù)業(yè)的綜合性企業(yè)集團(tuán),成為集合面授教學(xué)培訓(xùn)、網(wǎng)
達(dá)內(nèi)教育集團(tuán)成立于2002年,是一家由留學(xué)海歸創(chuàng)辦的高端職業(yè)教育培訓(xùn)機(jī)構(gòu),是中國一站式人才培養(yǎng)平臺、一站式人才輸送平臺。2014年4月3日在美國成功上市,融資1
浪潮集團(tuán)項(xiàng)目經(jīng)理。精通Java與.NET 技術(shù), 熟練的跨平臺面向?qū)ο箝_發(fā)經(jīng)驗(yàn),技術(shù)功底深厚。 授課風(fēng)格 授課風(fēng)格清新自然、條理清晰、主次分明、重點(diǎn)難點(diǎn)突出、引人入勝。
曾工作于聯(lián)想擔(dān)任系統(tǒng)開發(fā)工程師,曾在博彥科技股份有限公司擔(dān)任項(xiàng)目經(jīng)理從事移動互聯(lián)網(wǎng)管理及研發(fā)工作,曾創(chuàng)辦藍(lán)懿科技有限責(zé)任公司從事總經(jīng)理職務(wù)負(fù)責(zé)iOS教學(xué)及管理工作。
精通HTML5和CSS3;Javascript及主流js庫,具有快速界面開發(fā)的能力,對瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網(wǎng)頁制作和網(wǎng)頁游戲開發(fā)。
具有10 年的Java 企業(yè)應(yīng)用開發(fā)經(jīng)驗(yàn)。曾經(jīng)歷任德國Software AG 技術(shù)顧問,美國Dachieve 系統(tǒng)架構(gòu)師,美國AngelEngineers Inc. 系統(tǒng)架構(gòu)師。