最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

react+redux仿微信聊天界面

 更新時(shí)間:2019年06月21日 08:35:59   作者:xiaoyan2017  
這篇文章主要介紹了react+redux仿微信聊天IM實(shí)例|react仿微信界面 ,本文圖文并茂給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

一、項(xiàng)目概況

基于react+react-dom+react-router-dom+redux+react-redux+webpack2.0+react-photoswipe+swiper等技術(shù)混合開發(fā)的手機(jī)端仿微信界面聊天室——reactChatRoom,實(shí)現(xiàn)了聊天記錄下拉刷新、發(fā)送消息、表情(動(dòng)圖),圖片、視頻預(yù)覽,打賞、紅包等功能。

二、技術(shù)棧MVVM框架:

react / react-dom狀態(tài)管理:redux / react-redux頁(yè)面路由:react-router-dom彈窗插件:wcPop打包工具:webpack 2.0環(huán)境配置:node.js + cnpm圖片預(yù)覽:react-photoswipe輪播滑動(dòng):swiper

◆package.json依賴安裝:

{
 "name": "react-chatroom",
 "version": "0.1.0",
 "private": true,
 "author": "andy",
 "dependencies": {
  "react": "^16.8.6",
  "react-dom": "^16.8.6",
  "react-redux": "^7.0.3",
  "react-router-dom": "^5.0.0",
  "react-scripts": "0.9.x",
  "redux": "^4.0.1"
 },
 "devDependencies": {
  "jquery": "^2.2.3",
  "react-loadable": "^5.5.0",
  "react-photoswipe": "^1.3.0",
  "react-pullload": "^1.2.0",
  "redux-thunk": "^2.3.0",
  "swiper": "^4.5.0",
  "webpack": "^1.13.1",
  "webpack-dev-server": "^1.12.0"
 },
 "scripts": {
  "start": "set HOST=localhost&&set PORT=3003 && react-scripts start",
  "build": "react-scripts build",
  "test": "react-scripts test --env=jsdom",
  "eject": "react-scripts eject"
 }
}

◆ 入口頁(yè)面index.js配置

/*
 * @desc 入口頁(yè)面index.js
 */
import React from 'react';
import ReactDOM from 'react-dom';
// import {HashRouter as Router, Route} from 'react-router-dom'
import App from './App';
// 引入狀態(tài)管理
import {Provider} from 'react-redux'
import {store} from './store'
// 導(dǎo)入公共樣式
import './assets/fonts/iconfont.css'
import './assets/css/reset.css'
import './assets/css/layout.css'
// 引入wcPop彈窗樣式
import './assets/js/wcPop/skin/wcPop.css'
// 引入js
import './assets/js/fontSize'
ReactDOM.render(
 <Provider store={store}>
  <App />
 </Provider>,
 document.getElementById('app')
);

◆ 頁(yè)面App.js主模板

import React, { Component } from 'react';
import {HashRouter as Router, Route, Switch, Redirect} from 'react-router-dom'
import {connect} from 'react-redux'
import $ from 'jquery'
// 引入wcPop彈窗插件
import { wcPop } from './assets/js/wcPop/wcPop'
// 引入地址路由
import routers from './router'
// 導(dǎo)入頂部、底部tabbar
import HeaderBar from './components/header'
import TabBar from './components/tabbar'
class App extends Component {
 constructor(props){
  super(props)
  console.log('App主頁(yè)面參數(shù):\n' + JSON.stringify(props, null, 2))
 }
 render() {
  let token = this.props.token
  return (
   <Router>
    <div className="weChatIM__panel clearfix">
     <div className="we__chatIM-wrapper flexbox flex__direction-column">
      {/* 頂部 */}
      <Switch>
       <HeaderBar />
      </Switch>
      {/* 主頁(yè)面 */}
      <div className="wcim__container flex1">
       {/* 路由容器 */}
       <Switch>
        {
         routers.map((item, index) => {
          return <Route key={index} path={item.path} exact render={props => (
           !item.meta || !item.meta.requireAuth ? (<item.component {...props} />) : (
            token ? <item.component {...props} /> : <Redirect to={{pathname: '/login', state: {from: props.location}}} />
           )
          )} />
         })
        }
        {/* 初始化頁(yè)面跳轉(zhuǎn) */}
        <Redirect push to="/index" />
       </Switch>
      </div>
      {/* 底部tabbar */}
      <Switch>
       <TabBar />
      </Switch>
     </div>
    </div>
   </Router>
  );
 }
}
const mapStateToProps = (state) =>{
 return {
  ...state.auth
 }
}
export default connect(mapStateToProps)(App);

◆ react登錄、注冊(cè)模塊 / react登錄注冊(cè)驗(yàn)證

import React, { Component } from 'react';
import { Link } from 'react-router-dom'
import { connect } from 'react-redux';
import * as actions from '../../store/action'
// 引入wcPop彈窗插件
import { wcPop } from '../../assets/js/wcPop/wcPop.js'
class Login extends Component {
  constructor(props) {
    super(props)
    this.state = {
      tel: '',
      pwd: '',
      vcode: '',
      vcodeText: '獲取驗(yàn)證碼',
      disabled: false,
      time: 0
    }
  }
  componentDidMount(){
    if(this.props.token){
      this.props.history.push('/')
    }
  }
  render() {
    return (
      <div className="wcim__lgregWrapper flexbox flex__direction-column">
        ......
      </div>
    )
  }
  // 提交表單
  handleSubmit = (e) => {
    e.preventDefault();
    var that = this
    this.state.tel = this.refs.tel.value
    this.state.pwd = this.refs.pwd.value
    this.state.vcode = this.refs.vcode.value
    if (!this.state.tel) {
      wcPop({ content: '手機(jī)號(hào)不能為空!', style: 'background:#ff3b30;color:#fff;', time: 2 });
    } else if (!checkTel(this.state.tel)) {
      wcPop({ content: '手機(jī)號(hào)格式不正確!', style: 'background:#ff3b30;color:#fff;', time: 2 });
    } else if (!this.state.pwd) {
      wcPop({ content: '密碼不能為空!', style: 'background:#ff3b30;color:#fff;', time: 2 });
    } else if (!this.state.vcode) {
      wcPop({ content: '驗(yàn)證碼不能為空!', style: 'background:#ff3b30;color:#fff;', time: 2 });
    } else {
      // 獲取登錄之前的頁(yè)面地址
      let redirectUrl = this.props.location.state ? this.props.location.state.from.pathname : '/'
      // 設(shè)置token
      this.props.authToken(getToken())
      this.props.authUser(this.state.tel)
      wcPop({
        content: '注冊(cè)成功!', style: 'background:#41b883;color:#fff;', time: 2,
        end: function () {
          that.props.history.push(redirectUrl)
        }
      });
    }
  }
  // 60s倒計(jì)時(shí)
  handleVcode = (e) => {
    e.preventDefault();
    this.state.tel = this.refs.tel.value
    if (!this.state.tel) {
      wcPop({ content: '手機(jī)號(hào)不能為空!', style: 'background:#ff3b30;color:#fff;', time: 2 });
    } else if (!checkTel(this.state.tel)) {
      wcPop({ content: '手機(jī)號(hào)格式不正確!', style: 'background:#ff3b30;color:#fff;', time: 2 });
    } else {
      this.state.time = 60
      this.state.disabled = true
      this.countDown();
    }
  }
  countDown = (e) => {
    if(this.state.time > 0){
      this.state.time--
      this.setState({
        vcodeText: '獲取驗(yàn)證碼(' + this.state.time + ')'
      })
      // setTimeout(this.countDown, 1000);
      setTimeout(() => {
        this.countDown()
      }, 1000);
    }else{
      this.setState({
        time: 0,
        vcodeText: '獲取驗(yàn)證碼',
        disabled: false
      })
    }
  }
}
const mapStateToProps = (state) => {
  return {
    ...state.auth
  }
}
export default connect(mapStateToProps, {
  authToken: actions.setToken,
  authUser: actions.setUser
})(Login)

總結(jié)

以上所述是小編給大家介紹的react+redux仿微信聊天界面,希望對(duì)大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會(huì)及時(shí)回復(fù)大家的!

相關(guān)文章

  • react hooks使用Echarts圖表中遇到的情況及相關(guān)配置問題

    react hooks使用Echarts圖表中遇到的情況及相關(guān)配置問題

    這篇文章主要介紹了react hooks使用Echarts圖表中遇到的情況及相關(guān)配置問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-03-03
  • 一文學(xué)會(huì)使用Remix寫API接口

    一文學(xué)會(huì)使用Remix寫API接口

    這篇文章主要為大家介紹了一文學(xué)會(huì)Remix寫API接口實(shí)現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-04-04
  • React新擴(kuò)展函數(shù)setState與lazyLoad及hook介紹

    React新擴(kuò)展函數(shù)setState與lazyLoad及hook介紹

    這篇文章主要介紹了React新擴(kuò)展函數(shù)setState與lazyLoad及hook,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧
    2022-12-12
  • React與Redux之?dāng)?shù)組處理講解

    React與Redux之?dāng)?shù)組處理講解

    這篇文章主要介紹了React與Redux之?dāng)?shù)組處理講解,本篇文章通過簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-09-09
  • React拖拽調(diào)整大小的組件

    React拖拽調(diào)整大小的組件

    這篇文章主要為大家詳細(xì)介紹了React拖拽調(diào)整大小的組件,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-08-08
  • 關(guān)于hooks中useEffect()的使用總結(jié)

    關(guān)于hooks中useEffect()的使用總結(jié)

    這篇文章主要介紹了關(guān)于hooks中useEffect()的使用總結(jié),具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-01-01
  • React?Hook中的useState函數(shù)的詳細(xì)解析

    React?Hook中的useState函數(shù)的詳細(xì)解析

    Hook 就是 JavaScript 函數(shù),這個(gè)函數(shù)可以幫助你鉤入(hook into) React State以及生命周期等特性,這篇文章主要介紹了React?Hook?useState函數(shù)的詳細(xì)解析的相關(guān)資料,需要的朋友可以參考下
    2022-10-10
  • 詳解react-router-dom v6版本基本使用介紹

    詳解react-router-dom v6版本基本使用介紹

    本文主要介紹了react-router-dom v6版本基本使用介紹,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-03-03
  • 如何用webpack4.0擼單頁(yè)/多頁(yè)腳手架 (jquery, react, vue, typescript)

    如何用webpack4.0擼單頁(yè)/多頁(yè)腳手架 (jquery, react, vue, typescript)

    這篇文章主要介紹了如何用webpack4.0擼單頁(yè)/多頁(yè)腳手架 (jquery, react, vue, typescript),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-06-06
  • React路由鑒權(quán)的實(shí)現(xiàn)方法

    React路由鑒權(quán)的實(shí)現(xiàn)方法

    這篇文章主要介紹了React路由鑒權(quán)的實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-09-09

最新評(píng)論

汉中市| 合阳县| 绍兴县| 怀安县| 中方县| 芒康县| 苏尼特左旗| 额尔古纳市| 应用必备| 彝良县| 馆陶县| 台州市| 岳池县| 新泰市| 平阴县| 内乡县| 邳州市| 迁西县| 德令哈市| 闽侯县| 剑阁县| 罗平县| 漳州市| 大余县| 平山县| 洪雅县| 壶关县| 阳山县| 蒙阴县| 芮城县| 兴义市| 承德市| 西峡县| 秦安县| 揭西县| 教育| 沂水县| 英超| 临安市| 自贡市| 灵台县|