├── ...
├── ...
├── ...
├── public
│ ├── api // 模擬數據存放目錄
├── src // 開發目錄
│ ├── common // 公共組件
│ ├── pages // 頁面
│ │ ├── detail // 詳情頁
│ │ ├── home // 首頁
│ │ ├── login // 登陸頁
│ ├── statics // 靜態圖片資源
│ ├── store // 總存儲倉庫目錄
├── App.js
├── index.js
├── style.js // 樣式文件
├── ...
├── ...
├── ...
複製代碼
經過設置登陸狀態(true or false)來判斷是否登陸,同時經過ref屬性取到用戶名,傳給User組件將用戶名渲染到頁面。前端
點擊關注時獲取相應漫畫id並集合成數組;點擊取消關注時獲取當前項漫畫id,經過indexOf找到對應id後dispatch出漫畫信息,再將對應漫畫項移除。react
{
//this.followItem獲取當前已關注列表,this.list.id爲當前項漫畫id
isLogin && this.checkFollowed(this.followItem, this.list.id) ?
<Follow
className="btn other"
onClick={() => cancleFollowed(this.list.id, this.followItem)}
>
取消關注
</Follow> :
<Follow
className="btn other"
onClick={() => followCartoon(this.props.list, this.list.id, isLogin)}
>
關注
</Follow>
}
----------------------------------------------------------------------
checkFollowed(newList, id) {
const arr = [];
for(let i = 0; i < newList.length; i ++) {
// 集合已關注漫畫項id
arr.push(newList[i].id)
}
// 若當前項漫畫id存在於id集合中 返回true 顯示'取消關注'
if(arr.indexOf(id) >= 0) return true;
}
複製代碼
// 派發action,傳入當前項漫畫id及'已關注'漫畫數組
cancleFollowed(id, list) {
dispatch(actionCreators.cancleFollowed(id, list));
}
-----------------------------------------------------------------------------
export const cancleFollowed = (id, list) => {
return dispatch => {
const arr = [];
for (let i = 0; i < list.length; i++) {
// 判斷當前項漫畫是否存在於'已關注'列表
// 如有則移除當前項並將新列表數組派發給reducer
// reducer接受新列表數組並更新state,完成漫畫取關
if (list[i].id !== id) {
arr.push(list[i]);
}
}
dispatch(searchFollowed(arr));
}
};
複製代碼
能夠經過漫畫名及做者來搜索相應漫畫(固然都是假數據),頁面上顯示的漫畫我都作了其餘的我就沒作了哈。ios
這部分邏輯與'關注/取關'類似,也是經過獲取input的value值,用indexOf()方法判斷是否存在於關鍵詞列表裏(事先寫好的假數據,包括做品名和做者);再dispatch出對應項id,根據id集合對應漫畫項信息,而後就能夠渲染到界面上。git
寫這篇文章的目的就是記錄一下個人學習狀況,鼓勵本身繼續往下學,還想要整理一下個人思路(其實挺亂的吧),對這個項目感興趣的小夥伴能夠去查看個人項目地址(貼在下面啦)。github
本人前端新手,但願各位小(da)夥(lao)伴多給我一點意見,感謝!
歡迎交流٩(๑❛ᴗ❛๑)۶redux
微信:LYX0_0TXRYaxios
QQ:295510545
附上個人項目地址:Lestaapi