项目简介
主要是通过做一个多人在线多房间群聊的小项目、来练手全栈技术的结合运用。
项目源码:chat-vue-node
主要技术: vue2全家桶 + socket.io + node(express) + mongodb(mongoose)
环境配置: 需安装配置好 node,mongodb环境(参考:https://mit('updateGroupState', obj) } }, getters: { getChatState (state) { return state.chatState }, getGroupState (state) { return state.groupState } }})
在全局中更新state、获取state:
// 更新this.$store.dispatch('updateChatState', {account: null, nickName: null})// 获取this.$store.getters.getChatState
数据库接口api
module.exports = function (app) { app.all("*", function(req, res, next) { next() }) // api login 登录 app.get('/api/user/login', function (req, res) { // ... }) // api register 注册 app.get('/api/user/register', function (req, res) { // ... }) // getAccountGroup 获取可进入的房间 app.get('/api/user/getAccountGroup', function (req, res) { // ... }) // getGroupNumber 获取当前房间的群成员 app.get('/api/user/getGroupNumber', function (req, res) { // ... }) // api getChatLog 获取当前房间的聊天记录 app.get('/api/getChatLog', function (req, res) { // ... }) app.get('*', function(req, res){ res.end('404') })}
更多详细的实现,请看 源码chat-vue-node ,里面保留着开发摸索时的很多注释。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。