├── .browserslistrc ├── .eslintrc.js ├── .gitignore ├── LICENSE ├── README.md ├── jest.config.js ├── package-lock.json ├── package.json ├── postcss.config.js ├── public ├── favicon.ico └── index.html ├── src ├── App.vue ├── api │ └── index.js ├── assets │ ├── 401.gif │ ├── 404.png │ ├── bg.jpg │ ├── default.jpg │ ├── imgs │ │ ├── 1.png │ │ ├── 10.png │ │ ├── 11.png │ │ ├── 2.png │ │ ├── 3.png │ │ ├── 4.png │ │ ├── 5.png │ │ ├── 6.png │ │ ├── 7.png │ │ ├── 8.png │ │ └── 9.png │ ├── logo.png │ ├── user1.jpg │ ├── user2.jpg │ ├── user3.jpg │ ├── user4.jpg │ └── user5.jpg ├── components │ ├── Login.vue │ ├── NotFoundComponent.vue │ ├── ScrollTop.vue │ ├── articlehome │ │ ├── All.vue │ │ ├── Details.vue │ │ ├── PostArticle.vue │ │ ├── Top.vue │ │ └── allarticlehome.vue │ ├── backstagehome │ │ ├── ArticleManger.vue │ │ ├── BackStageHome.vue │ │ ├── Footer.vue │ │ ├── Header.vue │ │ ├── LoginBackStage.vue │ │ ├── Sidebar.vue │ │ ├── TypeManger.vue │ │ └── UserManger.vue │ ├── forumHome │ │ ├── Footer.vue │ │ ├── ForumHome.vue │ │ ├── Pageination.vue │ │ ├── Secend.vue │ │ ├── SecendTiles.vue │ │ ├── Tiles.vue │ │ └── Top.vue │ ├── register │ │ ├── FirstStep.vue │ │ ├── RegisterHome.vue │ │ ├── SecendStep.vue │ │ └── ThirdStep.vue │ └── userhome │ │ └── UserHome.vue ├── main.js ├── router │ └── index.js └── store │ ├── actions.js │ ├── getters.js │ ├── help.md │ ├── index.js │ └── mutations.js ├── tests └── unit │ └── example.spec.js ├── vue.config.js └── yarn.lock /.browserslistrc: -------------------------------------------------------------------------------- 1 | > 1% 2 | last 2 versions 3 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | env: { 4 | node: true 5 | }, 6 | extends: ["plugin:vue/essential", "@vue/prettier"], 7 | rules: { 8 | "no-console": process.env.NODE_ENV === "production" ? "error" : "off", 9 | "no-debugger": process.env.NODE_ENV === "production" ? "error" : "off" 10 | }, 11 | parserOptions: { 12 | parser: "babel-eslint" 13 | }, 14 | overrides: [ 15 | { 16 | files: [ 17 | "**/__tests__/*.{j,t}s?(x)", 18 | "**/tests/unit/**/*.spec.{j,t}s?(x)" 19 | ], 20 | env: { 21 | jest: true 22 | } 23 | } 24 | ] 25 | }; 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /dist 4 | 5 | # local env files 6 | .env.local 7 | .env.*.local 8 | 9 | # Log files 10 | npm-debug.log* 11 | yarn-debug.log* 12 | yarn-error.log* 13 | 14 | # Editor directories and files 15 | .idea 16 | .vscode 17 | *.suo 18 | *.ntvs* 19 | *.njsproj 20 | *.sln 21 | *.sw? 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 yOunGMonEy 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # forum 2 | 3 | 所用到的技术栈 4 | 5 | `springboot` 6 | 7 | `springsecurity` 8 | 9 | `vue` 10 | 11 | `vuex` 12 | 13 | `axios` 14 | 15 | `vue-router` 16 | 17 | `element-ui` 18 | 19 | `buefy-ui` 20 | 21 | `mysql` 22 | 23 | 后端项目地址:https://github.com/cp3geek/universityforum 24 | 25 | 后台项目跑起来再运行前端项目,不然获取不到数据,配置文件中更改数据库信息 26 | 27 | 28 | 帖子详情界面和发帖,登录界面使用v2ex论坛的样式 29 | 基本功能开发完了,但是有很多缺陷,先让项目跑起来再慢慢优化,希望各位大佬能给一些指导意见 30 | 31 | 32 | 33 | 项目部分截图 34 | ![image](src/assets/imgs/1.png) 35 | ![image](src/assets/imgs/2.png) 36 | ![image](src/assets/imgs/3.png) 37 | ![image](src/assets/imgs/4.png) 38 | ![image](src/assets/imgs/5.png) 39 | ![image](src/assets/imgs/6.png) 40 | ![image](src/assets/imgs/7.png) 41 | ![image](src/assets/imgs/8.png) 42 | ![image](src/assets/imgs/9.png) 43 | ![image](src/assets/imgs/10.png) 44 | ![image](src/assets/imgs/11.png) 45 | 46 | ## Project setup(安装依赖) 47 | ``` 48 | yarn install或者npm install 49 | ``` 50 | 51 | ### Compiles and hot-reloads for development(启动项目) 52 | ``` 53 | yarn run dev 或者npm run dev 54 | ``` 55 | 56 | ### Compiles and minifies for production(打包) 57 | ``` 58 | yarn run build 或者npm run build 59 | ``` 60 | 61 | 62 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | preset: "@vue/cli-plugin-unit-jest/presets/no-babel" 3 | }; 4 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "forum", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "serve": "vue-cli-service serve", 7 | "build": "vue-cli-service build", 8 | "lint": "vue-cli-service lint", 9 | "test:unit": "vue-cli-service test:unit" 10 | }, 11 | "dependencies": { 12 | "axios": "^0.19.0", 13 | "buefy": "^0.8.8", 14 | "element-ui": "^2.13.0", 15 | "font-awesome": "^4.7.0", 16 | "moment": "^2.24.0", 17 | "vue": "^2.6.10", 18 | "vue-axios": "^2.1.5", 19 | "vue-infinite-scroll": "^2.0.2", 20 | "vue-router": "^3.1.3", 21 | "vuex": "^3.0.1" 22 | }, 23 | "devDependencies": { 24 | "@vue/cli-plugin-eslint": "^4.0.0", 25 | "@vue/cli-plugin-unit-jest": "^4.0.0", 26 | "@vue/cli-service": "^4.0.0", 27 | "@vue/eslint-config-prettier": "^5.0.0", 28 | "@vue/test-utils": "1.0.0-beta.29", 29 | "babel-eslint": "^10.0.3", 30 | "eslint": "^5.16.0", 31 | "eslint-plugin-prettier": "^3.1.1", 32 | "eslint-plugin-vue": "^5.0.0", 33 | "less": "^3.0.4", 34 | "less-loader": "^5.0.0", 35 | "prettier": "^1.18.2", 36 | "vue-template-compiler": "^2.6.10" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | autoprefixer: {} 4 | } 5 | }; 6 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cp3geek/forum/4c560348ad7941d197bd05dbcf22fffbaa2d4347/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | forum 16 | 17 | 18 | 19 | 23 |
24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/App.vue: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 36 | 37 | 59 | -------------------------------------------------------------------------------- /src/api/index.js: -------------------------------------------------------------------------------- 1 | import axios from "axios"; 2 | import Qs from "qs"; 3 | import { SnackbarProgrammatic as Snackbar } from 'buefy' 4 | 5 | //全局默认配置 6 | axios.defaults.baseURL = "http://localhost:9090"; 7 | // axios.interceptors.request.use( 8 | // config => { 9 | // console.log(config); 10 | // return config; 11 | // }, 12 | // err => { 13 | // console.log(err); 14 | // } 15 | // );请求拦截 16 | axios.defaults.withCredentials = true //请求发送cookie 17 | 18 | 19 | axios.interceptors.response.use(res => { 20 | return res; 21 | }, () => { 22 | Snackbar.open({ 23 | message: '服务器被吃了', 24 | type: 'is-warning', 25 | position: 'is-top', 26 | actionText: 'Retry', 27 | indefinite: true, 28 | onAction: () => { 29 | this.$buefy.toast.open({ 30 | message: 'Action pressed', 31 | queue: false 32 | }) 33 | } 34 | }) 35 | }) 36 | 37 | //post传数据用data,get传参数用params 38 | export const adminLogin = (username, password) => { 39 | return axios.post("/loginbackstage", Qs.stringify({ username, password })); 40 | }; 41 | 42 | export const userLogin = (email, password) => { 43 | return axios.post( 44 | "http://localhost:9090/userlogin", 45 | Qs.stringify({ email, password }) 46 | ); 47 | }; 48 | 49 | export const getAllArticle = (page) => { 50 | return axios.post("/pagearticle", Qs.stringify({ page })); 51 | }; 52 | 53 | export const getAllArticleType = () => { 54 | return axios.post("/getallarticletype"); 55 | }; 56 | 57 | export const getArticleByTypeId = typeId => { 58 | return axios.post("/getarticlebytypeid", Qs.stringify({ typeId })); 59 | }; 60 | 61 | export const getHotArticleType = () => { 62 | return axios.post("/gethotarticletype"); 63 | }; 64 | 65 | export const getPageMain = pageNum => { 66 | return axios({ 67 | url: "/getpagearticle", 68 | params: { 69 | page: pageNum 70 | } 71 | }) 72 | }; 73 | export const getnew = () => { 74 | return axios("/getnew") 75 | }; 76 | 77 | export const gethotuser = () => { 78 | return axios("/hotuser") 79 | }; 80 | export const register = (userName, userPassword, userShow, userEmail, userPhone, userSex) => { 81 | 82 | return axios.post("/register", Qs.stringify({ userName, userPassword, userShow, userEmail, userPhone, userSex })) 83 | 84 | }; 85 | export const getcomment = (artId) => { 86 | return axios.post("/getComment", Qs.stringify({ artId })) 87 | }; 88 | export const newcomment = (comArtId, text, comUserId) => { 89 | return axios.post("/postcomment", Qs.stringify({ comArtId, text, comUserId })) 90 | }; 91 | export const newpost = (userId, title, text, select) => { 92 | return axios.post("/newpost", Qs.stringify({ userId, title, text, select })) 93 | } 94 | 95 | export const findartbyuserid = (userId) => { 96 | return axios.post("/findartbyuserid", Qs.stringify({ userId })) 97 | } 98 | 99 | export const getuserlist = () => { 100 | return axios.post("/getuserlist") 101 | } 102 | 103 | 104 | -------------------------------------------------------------------------------- /src/assets/401.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cp3geek/forum/4c560348ad7941d197bd05dbcf22fffbaa2d4347/src/assets/401.gif -------------------------------------------------------------------------------- /src/assets/404.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cp3geek/forum/4c560348ad7941d197bd05dbcf22fffbaa2d4347/src/assets/404.png -------------------------------------------------------------------------------- /src/assets/bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cp3geek/forum/4c560348ad7941d197bd05dbcf22fffbaa2d4347/src/assets/bg.jpg -------------------------------------------------------------------------------- /src/assets/default.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cp3geek/forum/4c560348ad7941d197bd05dbcf22fffbaa2d4347/src/assets/default.jpg -------------------------------------------------------------------------------- /src/assets/imgs/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cp3geek/forum/4c560348ad7941d197bd05dbcf22fffbaa2d4347/src/assets/imgs/1.png -------------------------------------------------------------------------------- /src/assets/imgs/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cp3geek/forum/4c560348ad7941d197bd05dbcf22fffbaa2d4347/src/assets/imgs/10.png -------------------------------------------------------------------------------- /src/assets/imgs/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cp3geek/forum/4c560348ad7941d197bd05dbcf22fffbaa2d4347/src/assets/imgs/11.png -------------------------------------------------------------------------------- /src/assets/imgs/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cp3geek/forum/4c560348ad7941d197bd05dbcf22fffbaa2d4347/src/assets/imgs/2.png -------------------------------------------------------------------------------- /src/assets/imgs/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cp3geek/forum/4c560348ad7941d197bd05dbcf22fffbaa2d4347/src/assets/imgs/3.png -------------------------------------------------------------------------------- /src/assets/imgs/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cp3geek/forum/4c560348ad7941d197bd05dbcf22fffbaa2d4347/src/assets/imgs/4.png -------------------------------------------------------------------------------- /src/assets/imgs/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cp3geek/forum/4c560348ad7941d197bd05dbcf22fffbaa2d4347/src/assets/imgs/5.png -------------------------------------------------------------------------------- /src/assets/imgs/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cp3geek/forum/4c560348ad7941d197bd05dbcf22fffbaa2d4347/src/assets/imgs/6.png -------------------------------------------------------------------------------- /src/assets/imgs/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cp3geek/forum/4c560348ad7941d197bd05dbcf22fffbaa2d4347/src/assets/imgs/7.png -------------------------------------------------------------------------------- /src/assets/imgs/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cp3geek/forum/4c560348ad7941d197bd05dbcf22fffbaa2d4347/src/assets/imgs/8.png -------------------------------------------------------------------------------- /src/assets/imgs/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cp3geek/forum/4c560348ad7941d197bd05dbcf22fffbaa2d4347/src/assets/imgs/9.png -------------------------------------------------------------------------------- /src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cp3geek/forum/4c560348ad7941d197bd05dbcf22fffbaa2d4347/src/assets/logo.png -------------------------------------------------------------------------------- /src/assets/user1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cp3geek/forum/4c560348ad7941d197bd05dbcf22fffbaa2d4347/src/assets/user1.jpg -------------------------------------------------------------------------------- /src/assets/user2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cp3geek/forum/4c560348ad7941d197bd05dbcf22fffbaa2d4347/src/assets/user2.jpg -------------------------------------------------------------------------------- /src/assets/user3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cp3geek/forum/4c560348ad7941d197bd05dbcf22fffbaa2d4347/src/assets/user3.jpg -------------------------------------------------------------------------------- /src/assets/user4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cp3geek/forum/4c560348ad7941d197bd05dbcf22fffbaa2d4347/src/assets/user4.jpg -------------------------------------------------------------------------------- /src/assets/user5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cp3geek/forum/4c560348ad7941d197bd05dbcf22fffbaa2d4347/src/assets/user5.jpg -------------------------------------------------------------------------------- /src/components/Login.vue: -------------------------------------------------------------------------------- 1 | 134 | 135 | 136 | 137 | 138 | 172 | 173 | 174 | -------------------------------------------------------------------------------- /src/components/NotFoundComponent.vue: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/components/ScrollTop.vue: -------------------------------------------------------------------------------- 1 | 12 | 13 | 100 | 101 | 112 | 113 | -------------------------------------------------------------------------------- /src/components/articlehome/All.vue: -------------------------------------------------------------------------------- 1 | 112 | 113 | 114 | 243 | 244 | -------------------------------------------------------------------------------- /src/components/articlehome/Details.vue: -------------------------------------------------------------------------------- 1 | 234 | 235 | 355 | 356 | -------------------------------------------------------------------------------- /src/components/articlehome/PostArticle.vue: -------------------------------------------------------------------------------- 1 | 208 | 209 | 210 | 211 | 236 | 237 | -------------------------------------------------------------------------------- /src/components/articlehome/Top.vue: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/components/articlehome/allarticlehome.vue: -------------------------------------------------------------------------------- 1 | 8 | 9 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/components/backstagehome/ArticleManger.vue: -------------------------------------------------------------------------------- 1 | 16 | 17 | -------------------------------------------------------------------------------- /src/components/backstagehome/BackStageHome.vue: -------------------------------------------------------------------------------- 1 | 21 | 22 | 23 | 24 | 44 | 45 | 46 | 82 | -------------------------------------------------------------------------------- /src/components/backstagehome/Footer.vue: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/components/backstagehome/Header.vue: -------------------------------------------------------------------------------- 1 | 24 | 25 | 31 | 32 | -------------------------------------------------------------------------------- /src/components/backstagehome/LoginBackStage.vue: -------------------------------------------------------------------------------- 1 | 19 | 20 | 50 | 51 | -------------------------------------------------------------------------------- /src/components/backstagehome/Sidebar.vue: -------------------------------------------------------------------------------- 1 | 27 | 28 | 29 | 35 | 36 | -------------------------------------------------------------------------------- /src/components/backstagehome/TypeManger.vue: -------------------------------------------------------------------------------- 1 | 27 | 28 | -------------------------------------------------------------------------------- /src/components/backstagehome/UserManger.vue: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 52 | 53 | -------------------------------------------------------------------------------- /src/components/forumHome/Footer.vue: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 26 | 27 | -------------------------------------------------------------------------------- /src/components/forumHome/ForumHome.vue: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 | 33 | 34 | -------------------------------------------------------------------------------- /src/components/forumHome/Pageination.vue: -------------------------------------------------------------------------------- 1 | 24 | 25 | -------------------------------------------------------------------------------- /src/components/forumHome/Secend.vue: -------------------------------------------------------------------------------- 1 | 29 | 32 | 33 | -------------------------------------------------------------------------------- /src/components/forumHome/SecendTiles.vue: -------------------------------------------------------------------------------- 1 | 134 | 135 | 220 | 221 | 222 | -------------------------------------------------------------------------------- /src/components/forumHome/Tiles.vue: -------------------------------------------------------------------------------- 1 | 97 | 98 | 183 | 184 | 197 | -------------------------------------------------------------------------------- /src/components/forumHome/Top.vue: -------------------------------------------------------------------------------- 1 | 107 | 108 | 151 | -------------------------------------------------------------------------------- /src/components/register/FirstStep.vue: -------------------------------------------------------------------------------- 1 | 27 | 28 | 29 | 72 | 73 | -------------------------------------------------------------------------------- /src/components/register/RegisterHome.vue: -------------------------------------------------------------------------------- 1 | 18 | 19 | 20 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/components/register/SecendStep.vue: -------------------------------------------------------------------------------- 1 | 29 | 30 | 74 | 75 | 86 | -------------------------------------------------------------------------------- /src/components/register/ThirdStep.vue: -------------------------------------------------------------------------------- 1 | 34 | 35 | 79 | 80 | -------------------------------------------------------------------------------- /src/components/userhome/UserHome.vue: -------------------------------------------------------------------------------- 1 | 149 | 150 | 151 | 184 | 185 | 186 | -------------------------------------------------------------------------------- /src/main.js: -------------------------------------------------------------------------------- 1 | import Vue from "vue"; 2 | import App from "./App.vue"; 3 | import router from "./router"; 4 | import store from "./store"; 5 | import Buefy from "buefy"; 6 | import "buefy/dist/buefy.css"; 7 | import axios from "axios"; 8 | import VueAxios from "vue-axios"; 9 | import ElementUI from "element-ui"; 10 | import "element-ui/lib/theme-chalk/index.css"; 11 | import moment from 'moment'//导入文件 12 | // import infiniteScroll from "vue-infinite-scroll" 13 | // import Qs from "qs"; 14 | 15 | 16 | 17 | // Vue.use(infiniteScroll) 18 | Vue.prototype.$moment = moment;//赋值使用 19 | moment.locale('zh-cn')//国际化,中文 20 | Vue.use(Buefy); 21 | Vue.use(ElementUI); 22 | Vue.config.productionTip = false; 23 | Vue.use(VueAxios, axios); 24 | 25 | new Vue({ 26 | router, 27 | store, 28 | axios, 29 | // render: function (h) { 30 | // return h(App); 31 | // } 32 | render: h => h(App) 33 | }).$mount("#app"); 34 | 35 | // axios.all([axios.post("http://localhost:9090/getuser", Qs.stringify({ 36 | // username: "sasd", 37 | // password: 123 38 | // })), axios.post("http://localhost:9090/getuser", 39 | // Qs.stringify({ 40 | // username: "saaa", 41 | // password: 1234 42 | // }))]).then(axios.spread((res1, res2) => { 43 | // console.log(res1) 44 | // console.log(res2) 45 | // })) 46 | 47 | // axios({ 48 | // url: "http://localhost:9090/getadmin", 49 | // params: { 50 | // username: "aaaa" 51 | // } 52 | 53 | // }) 54 | 55 | // axios.post("http://localhost:9090/getadmin", Qs.stringify({ 56 | // username: '55551', 57 | // password: 1245 58 | // })) 59 | router.beforeEach((to, from, next) => { 60 | if (to.matched.some(m => m.meta.requireAuth)) { 61 | 62 | // 对路由进行验证 63 | if (store.state.isLogin) { // 已经登陆 64 | next() // 正常跳转到你设置好的页面 65 | } else { 66 | // 未登录则跳转到登陆界面 67 | next({ path: '/login' }) 68 | } 69 | } else { 70 | next() 71 | } 72 | }) 73 | 74 | 75 | -------------------------------------------------------------------------------- /src/router/index.js: -------------------------------------------------------------------------------- 1 | import Vue from "vue"; 2 | import VueRouter from "vue-router"; 3 | import NotFoundComponent from "../components/NotFoundComponent.vue"; 4 | 5 | Vue.use(VueRouter); 6 | 7 | const routes = [ 8 | { 9 | path: "/", 10 | name: "forumhome", 11 | component: () => import("../components/forumHome/ForumHome.vue") 12 | }, 13 | { 14 | path: "/login", 15 | name: "login", 16 | component: () => import("../components/Login.vue") 17 | }, 18 | { 19 | path: "/loginbackstage", 20 | name: "loginbackstage", 21 | component: () => import("../components/backstagehome/LoginBackStage.vue") 22 | }, 23 | 24 | { 25 | path: "/backstagehome", 26 | component: () => import("../components/backstagehome/BackStageHome.vue"), 27 | children: [ 28 | { 29 | path: "/usermanger", 30 | name: "usermanger", 31 | component: () => import("../components/backstagehome/UserManger.vue") 32 | }, 33 | { 34 | path: "/articlemanger", 35 | name: "articlemanger", 36 | component: () => import("../components/backstagehome/ArticleManger.vue") 37 | }, 38 | { 39 | path: "/typemanger", 40 | name: "typemanger", 41 | component: () => import("../components/backstagehome/TypeManger.vue") 42 | } 43 | ] 44 | }, 45 | { 46 | path: "/userhome", 47 | meta: { requireAuth: true }, 48 | component: () => import("../components/userhome/UserHome") 49 | }, 50 | { 51 | path: "/allarticlehome", 52 | component: () => import("../components/articlehome/Allarticlehome") 53 | }, 54 | 55 | { 56 | path: "/registerhome", 57 | component: () => import("../components/register/RegisterHome") 58 | }, 59 | 60 | { 61 | path: "*", component: NotFoundComponent 62 | }, 63 | { 64 | path: "/details", 65 | name: "Details", 66 | component: () => import("../components/articlehome/Details") 67 | }, 68 | { 69 | path: "/postarticle", 70 | name: "PostArticle", 71 | component: () => import("../components/articlehome/PostArticle") 72 | } 73 | , 74 | ]; 75 | 76 | const router = new VueRouter({ 77 | mode: "history", 78 | base: process.env.BASE_URL, 79 | routes 80 | }); 81 | 82 | 83 | 84 | export default router; 85 | -------------------------------------------------------------------------------- /src/store/actions.js: -------------------------------------------------------------------------------- 1 | import { getPageMain } from "@/api" 2 | 3 | export default { 4 | //context:上下文,actions中的默认参数,理解成store对象 5 | aLogin(context, payload) { 6 | setTimeout(() => { 7 | context.commit('login', payload.user) 8 | console.log(payload.message); 9 | payload.success(); 10 | }, 1000) 11 | }, 12 | 13 | 14 | 15 | getpagemain(context) { 16 | getPageMain().then(res => { 17 | context.commit('getpagemain', { 18 | info: res.data.content, 19 | totalElements: res.data.totalElements 20 | } 21 | 22 | ) 23 | }).catch() 24 | }, 25 | 26 | changepage(context, number) { 27 | getPageMain(number).then(res => { 28 | context.commit('getpagemain', { 29 | info: res.data.content 30 | }) 31 | }).catch() 32 | }, 33 | 34 | 35 | 36 | 37 | 38 | 39 | }//包含多个对应事件回调函数得对象,主要是异步操作 -------------------------------------------------------------------------------- /src/store/getters.js: -------------------------------------------------------------------------------- 1 | export default { 2 | //抽离 3 | 4 | 5 | //如果需要传入参数,则可返回一个回调函数 6 | //例如:组件中{{$store.getters.moreAgestu(10)}} 7 | // moreAgestu(state) { 8 | // return function (age) { 9 | // return state.students.filter(s => s.age > age); 10 | // } 11 | // } 12 | 13 | 14 | 15 | 16 | // more20stu(state) { 17 | // return state.students.filter(s => s.age > 20);返回的是结果 18 | // }, 19 | //在组件中写{{$store.getters.more20stu}} 20 | //getters还可以作为参数 21 | //例如: 22 | // more20stulength(state, getters) { 23 | // return getters.more20stu.length;结果 24 | // } 25 | //powcounter(state) { 26 | //return state.counter * state.counter;结果 27 | //} 28 | //组件中使用getters 29 | //{{$store.getters.powcounter}} 30 | } -------------------------------------------------------------------------------- /src/store/help.md: -------------------------------------------------------------------------------- 1 | 如果是父子组件,则状态管理不需要用vuex,只需通过props,父组件向子组件传值即可 2 | 3 | 4 | 例如父组件中 5 | `` 13 | 14 | `` 27 | 28 | 子组件中 29 | `` 34 | 35 | `` 42 | 43 | 44 | 45 | 46 | vue的响应式原理 47 | 48 | 增加: 49 | Vue.set(state.xxx,key,value|number) 50 | 删除: 51 | vue.delete(state.info,'age') 52 | 53 | Mutation同步函数 54 | Actions异步操作 55 | 56 | 开发注册功能,进度放慢,因为一些考试 -------------------------------------------------------------------------------- /src/store/index.js: -------------------------------------------------------------------------------- 1 | import Vue from "vue"; 2 | import Vuex from "vuex"; 3 | import getters from '../store/getters'; 4 | import mutations from '../store/mutations'; 5 | import actions from '../store/actions'; 6 | Vue.use(Vuex); 7 | 8 | //全局状态管理,相当于一个公共变量,并且是响应式的,任何一个组件更改其内容,可以响应式更新页面 9 | 10 | // const moduleA = { 11 | // state: { 12 | // name:"dddd" 13 | // }, 14 | // getters: {}, 15 | // actions: {}, 16 | // mutations:{} 17 | // } 18 | 19 | export default new Vuex.Store({ 20 | 21 | state: { 22 | isLogin: window.localStorage.getItem('isLogin' || '[]') == null ? '' : true, 23 | user: { 24 | userName: window.localStorage.getItem('user' || '[]') == null ? '' : JSON.parse(window.localStorage.getItem('user' || '[]')).userName, 25 | userId: window.localStorage.getItem('user' || '[]') == null ? '' : JSON.parse(window.localStorage.getItem('user' || '[]')).userId, 26 | userBlog: window.localStorage.getItem('user' || '[]') == null ? '' : JSON.parse(window.localStorage.getItem('user' || '[]')).userBlog, 27 | userConcern: window.localStorage.getItem('user' || '[]') == null ? '' : JSON.parse(window.localStorage.getItem('user' || '[]')).userConcern, 28 | userFans: window.localStorage.getItem('user' || '[]') == null ? '' : JSON.parse(window.localStorage.getItem('user' || '[]')).userFans, 29 | userImg: window.localStorage.getItem('user' || '[]') == null ? '' : JSON.parse(window.localStorage.getItem('user' || '[]')).userImg, 30 | userShow: window.localStorage.getItem('user' || '[]') == null ? '' : JSON.parse(window.localStorage.getItem('user' || '[]')).userShow, 31 | userSex: window.localStorage.getItem('user' || '[]') == null ? '' : JSON.parse(window.localStorage.getItem('user' || '[]')).userSex, 32 | userPhone: window.localStorage.getItem('user' || '[]') == null ? '' : JSON.parse(window.localStorage.getItem('user' || '[]')).userPhone, 33 | }, 34 | info: [ 35 | { 36 | article: { 37 | artId: 0, 38 | artUserId: 1, 39 | artTitle: "", 40 | artTypeId: 0, 41 | artContent: "", 42 | artCommentId: 0, 43 | artCreTime: "", 44 | artView: "", 45 | artComNum: 0, 46 | artHotNum: 0, 47 | artLikeNum: 0 48 | }, 49 | user: { 50 | userId: 0, 51 | userPassword: 0, 52 | userName: "", 53 | userEmail: "", 54 | userSex: "", 55 | userPhone: "", 56 | userStatus: 0, 57 | userTime: "", 58 | userShow: "", 59 | userBlog: "", 60 | userImg: "", 61 | userFans: 0, 62 | userConcern: 0 63 | } 64 | } 65 | ], 66 | totalElements: 16, 67 | registeruser: { 68 | userName: "", 69 | userEmail: "", 70 | userSex: "", 71 | userShow: "", 72 | userPhone: "", 73 | userPassword: "" 74 | } 75 | }, 76 | mutations, 77 | actions, 78 | modules: {}, 79 | getters 80 | }); 81 | -------------------------------------------------------------------------------- /src/store/mutations.js: -------------------------------------------------------------------------------- 1 | export default { 2 | //mutations提交风格ccc(state,payload){} 3 | //mutation包括两部分1:字符串的事件类型2:一个回调函数,该回调函数的第一个参数就是state 4 | //login是事件类型,后面是回调函数 5 | login(state, user) { 6 | state.isLogin = true; 7 | state.user = user; 8 | window.localStorage.setItem('user', JSON.stringify(user)); 9 | window.localStorage.setItem('isLogin', true) 10 | }, 11 | logout(state) { 12 | state.isLogin = ''; 13 | window.localStorage.removeItem('user') 14 | window.localStorage.removeItem('isLogin') 15 | }, 16 | 17 | getpagemain(state, payload) { 18 | state.info = payload.info; 19 | // state.totalPages = payload.totalPages; 20 | state.totalElements = payload.totalElements; 21 | }, 22 | 23 | first(state, payload) { 24 | state.registeruser.userName = payload.userName; 25 | state.registeruser.userPassword = payload.userPassword 26 | state.registeruser.userEmail = payload.userEmail 27 | }, 28 | 29 | secend(state, payload) { 30 | state.registeruser.userPhone = payload.userPhone; 31 | state.registeruser.userSex = payload.userSex; 32 | state.registeruser.userShow = payload.userShow; 33 | }, 34 | 35 | details(state, info) { 36 | state.info = info 37 | } 38 | 39 | //带参数 40 | // login1(state, conut) { 41 | // state.isLogin = conut; 42 | // } 43 | // //组件中定义方法@click="ccc" 44 | // ccc(){ 45 | // this.store.commit('login1',true) 46 | // } 47 | 48 | 49 | 50 | //方法 51 | }//包含多个更新state函数得对象 -------------------------------------------------------------------------------- /tests/unit/example.spec.js: -------------------------------------------------------------------------------- 1 | import { shallowMount } from "@vue/test-utils"; 2 | import HelloWorld from "@/components/HelloWorld.vue"; 3 | 4 | describe("HelloWorld.vue", () => { 5 | it("renders props.msg when passed", () => { 6 | const msg = "new message"; 7 | const wrapper = shallowMount(HelloWorld, { 8 | propsData: { msg } 9 | }); 10 | expect(wrapper.text()).toMatch(msg); 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /vue.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | publicPath: "/", 3 | 4 | }; 5 | --------------------------------------------------------------------------------