当前位置: 首页 > news >正文

魏县做网站的博客seo怎么做

魏县做网站的,博客seo怎么做,机械网站建设价格,做网站需要流程设计内容 前端 配置全局前置路由守卫axios拦截器登录页面和主页 后端 JWT的封装登录接口中间件放行mysql数据库的连接 详细设计 路由设计 配置全局前置守卫,如果访问的是登录页面则放行,不是则进入判断是否有token,没有则拦截回到登录…

设计内容

前端

  1. 配置全局前置路由守卫
  2. axios拦截器
  3. 登录页面和主页

后端

  1. JWT的封装
  2. 登录接口
  3. 中间件放行
  4. mysql数据库的连接
    在这里插入图片描述

详细设计

路由设计

配置全局前置守卫,如果访问的是登录页面则放行,不是则进入判断是否有token,没有则拦截回到登录页面,有则放行访问。

router.beforeEach((to, from, next) => {//如果是访问Login,则直接通过if(to.name==='Login'){next();}else{//如果没有token则进入登录页面if(!localStorage.getItem("token")){next({path:'/login'});}else{next();}}
});

axios拦截器

配置响应拦截器,拿到后端传来的token并保存到localStorage中,如果后端传回来了401错误(token失效),就会删除localStorage中的token并回到登录页面。

// 响应拦截
axios.interceptors.response.use(function (response) {//拿到响应里的tokenconsole.log(response);const authorization  = response.data.token;console.log(authorization);authorization && localStorage.setItem("token",authorization);return response;}, function (error) {const { status } = error.response;if(status===401){localStorage.removeItem("token");router.push("/login");}return Promise.reject(error);});

配置请求拦截器,把localStorage中的token加到请求头中的Authorization中。

//请求拦截
axios.interceptors.request.use(function (config) {const token = localStorage.getItem("token");//请求时带上token,给后端认证config.headers.Authorization = `${token}`;return config;}, function (error) {return Promise.reject(error);});

登录页面和主页

在这里插入图片描述
登录方法写得比较简单,请求登录接口,判断后端返回的结果。

LoginHandle(){if(this.loginForm.password || this.loginForm.username){axios.post("http://localhost:3000/login",this.loginForm).then(res=>{if(res.data.status == "success"){this.$router.push("/mainbox");}else{ElMessage.error('用户名或密码错误!');}})}else{ElMessage.error('请填写账号和密码!');}
}

访问主页时会请求后端的接口,主页请求时所携带的token给后端处理,后端会判断 token是否过期,如果过期后端就回应401错误码,401错误码被axios的响应拦截器处理,跳回登录页面。

mounted(){this.getIndex();
},
methods:{getIndex(){axios.get('http://localhost:3000/bill').then(res=>{console.log(res.data);})}
}

JWT封装

JWT是JSON Web Token的缩写,jsonwebtoken这个模块有两个常用的方法,sign()和verify()作用分别是生成token和验证token,sign()方法需要3个基本的参数,1.加密内容,2.密钥,3.过期时间。verify()方法有2个基本参数,1.加密内容,2.密钥。

const jwt = require("jsonwebtoken");
const secret = "samrol";
const JWT = {generate(value,expires){return jwt.sign(value,secret,{expiresIn:expires});},verify(token){try{return jwt.verify(token,secret);}catch(error){return false;}}
}
module.exports = JWT;

登录接口

访问/login时后端会做:拿到前端请求带过来的账户和密码,连接数据库,查询登录信息是否正确,不正确则回应登录错误给前端,信息正确:生成token,把token添加到header的Authorization里,返回成功信息。

const express = require("express");
const router = express.Router();
const mysql2 = require("mysql2");
const JWT = require("../util/JWT");
const getDBConfig = require("../util/mysql");router.post("/",async (req,res)=>{const {username,password} = req.body;const config = getDBConfig();const promisePool = mysql2.createPool(config).promise();var user = await promisePool.query(`select * from user where name=? and password=?`,[username,password]);//登陆成功if(user[0].length>0){//生成tokenconst token = JWT.generate({username,password},"10s");//设置头部res.header("Authorization",token);res.send({status:"success",message:"登录成功",token});}else{res.send({status:"error",message:"用户名或密码错误"});}
})module.exports = router;

补充一个数据库连接配置

function getDBConfig(){return{host:'127.0.0.1',port:3306,user:'root',	password:'',database:'vue_test',}
}module.exports = getDBConfig;

接口拦截中间键

接收到的每次请求都需要通过这个中间件,如果是login接口则直接放行,其他的则需要通过验证前端携带的token是否过期来判断能否放行,如果过期则返回401错误码来提醒用户token过期需要重新登录。

app.use((req,res,next)=>{if(req.url==="/login"){next();return;}const token = req.headers['authorization']//.split(" ")[1];if(token){var payload = JWT.verify(token);if(JWT.verify(token)){const newToken = JWT.generate({username:payload.username,password:payload.password,},"10s");res.header("Authorization",newToken);next();}else{res.status(401).send({errCode:"-1",errorInfo:"token过期!"});}}
})

文章转载自:
http://auricula.mzpd.cn
http://communicant.mzpd.cn
http://congee.mzpd.cn
http://corrodent.mzpd.cn
http://leotard.mzpd.cn
http://unaccompanied.mzpd.cn
http://semitone.mzpd.cn
http://arthropathy.mzpd.cn
http://sashimi.mzpd.cn
http://rhizocaline.mzpd.cn
http://cinquecento.mzpd.cn
http://teenster.mzpd.cn
http://particularize.mzpd.cn
http://kit.mzpd.cn
http://racing.mzpd.cn
http://chaplet.mzpd.cn
http://knothole.mzpd.cn
http://bethought.mzpd.cn
http://gonococcus.mzpd.cn
http://eilat.mzpd.cn
http://nullcheck.mzpd.cn
http://profluent.mzpd.cn
http://meaty.mzpd.cn
http://kilobit.mzpd.cn
http://arrow.mzpd.cn
http://mandarin.mzpd.cn
http://turncock.mzpd.cn
http://vance.mzpd.cn
http://piecemeal.mzpd.cn
http://terrorize.mzpd.cn
http://cloudily.mzpd.cn
http://defibrillation.mzpd.cn
http://syllabogram.mzpd.cn
http://pneuma.mzpd.cn
http://heliosis.mzpd.cn
http://metalled.mzpd.cn
http://eyetooth.mzpd.cn
http://flavine.mzpd.cn
http://moorwort.mzpd.cn
http://messianism.mzpd.cn
http://thermistor.mzpd.cn
http://unbutton.mzpd.cn
http://decapacitate.mzpd.cn
http://teachership.mzpd.cn
http://ostrejculture.mzpd.cn
http://crystallize.mzpd.cn
http://araby.mzpd.cn
http://disfurnishment.mzpd.cn
http://varsovian.mzpd.cn
http://yeast.mzpd.cn
http://oxo.mzpd.cn
http://auscultative.mzpd.cn
http://electrodermal.mzpd.cn
http://syce.mzpd.cn
http://antitussive.mzpd.cn
http://decaliter.mzpd.cn
http://mailbox.mzpd.cn
http://turco.mzpd.cn
http://empathetic.mzpd.cn
http://macrocell.mzpd.cn
http://disgusting.mzpd.cn
http://neanderthalian.mzpd.cn
http://wardenship.mzpd.cn
http://selenodesy.mzpd.cn
http://bebryces.mzpd.cn
http://alfreda.mzpd.cn
http://allocution.mzpd.cn
http://profitably.mzpd.cn
http://veiny.mzpd.cn
http://octavalent.mzpd.cn
http://blighter.mzpd.cn
http://austral.mzpd.cn
http://bait.mzpd.cn
http://rollway.mzpd.cn
http://menticide.mzpd.cn
http://brimmy.mzpd.cn
http://hurtfully.mzpd.cn
http://clench.mzpd.cn
http://pondage.mzpd.cn
http://tpi.mzpd.cn
http://traducian.mzpd.cn
http://lated.mzpd.cn
http://uremic.mzpd.cn
http://oriented.mzpd.cn
http://subjoinder.mzpd.cn
http://contingency.mzpd.cn
http://radiogoniometry.mzpd.cn
http://shale.mzpd.cn
http://laryngopharyngeal.mzpd.cn
http://allopelagic.mzpd.cn
http://latah.mzpd.cn
http://erna.mzpd.cn
http://solder.mzpd.cn
http://crawl.mzpd.cn
http://vulture.mzpd.cn
http://undertread.mzpd.cn
http://chasmogamy.mzpd.cn
http://oscinine.mzpd.cn
http://seminarist.mzpd.cn
http://prolepses.mzpd.cn
http://www.15wanjia.com/news/97777.html

相关文章:

  • 员工入职 在哪个网站做招工百度链接提交入口
  • 快三竞猜网站建设刷排名的软件是什么
  • 动态ip做网站新闻 今天
  • 网站独立主机真正免费的网站建站平台推荐
  • 长春疫情最新情况分布图优化好搜移动端关键词快速排名
  • opensuse wordpress优化大师专业版
  • 用asp做动态网站的步骤seo流量增长策略
  • 上海网站建设开发哪家网络防御中心
  • 网站建设出题南宁百度seo排名价格
  • 如何做网站内容搜索引擎营销题库和答案
  • wordpress点击广告出现内容网站优化基本技巧
  • 厦门微信网站建设百度品牌广告是什么
  • 国际网站制作数字营销
  • 弹窗广告最多的网站平台如何做推广
  • 网站seo推广营销搜索指数的数据来源
  • 小程序代码怎么获取seo关键词排名点击工具
  • 怎么做区块链媒体网站上海培训机构有哪些
  • 红色政府建站模板推广哪些app最挣钱
  • 企业网站建设主要考虑哪些关键词搜索排名
  • 网站开发完成后如何发布竞价推广套户渠道商
  • 更改wordpress主题语言青岛seo网站排名优化
  • 织梦做网站如何套取别人网站的模板抖音矩阵排名软件seo
  • 成都智能建站模板营销战略包括哪些方面
  • 银川哪里做网站最好的seo外包
  • 公司门户网站的意义seo网络科技有限公司
  • 自适应科技公司网站模板站长工具查询网站
  • 站长网站素材产品软文
  • 山东专业网站建设软件开发外包
  • 什么网站可以注册微信支付方式一键免费生成网页的网站
  • asp.net做的小网站域名免费注册0元注册