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

网站推广的策略有哪些排名优化

网站推广的策略有哪些,排名优化,类似淘宝的网站怎么做,asp业务网站若依官方的前后端分离版中,前端用的Vue2,这个有人改了Vue3的前端出来。刚好用来学习: https://gitee.com/weifengze/RuoYi-Vue3 运行前后端项目 首先运行项目 启动前端,npm install、npm run dev 启动后端,按教程配置…

若依官方的前后端分离版中,前端用的Vue2,这个有人改了Vue3的前端出来。刚好用来学习:
https://gitee.com/weifengze/RuoYi-Vue3

运行前后端项目

首先运行项目
启动前端,npm installnpm run dev
启动后端,按教程配置数据库、redis环境,启动即可

在这里插入图片描述

页面实现文件在:RUOYI-VUE3/src/views/login.vue

验证码

function getCode() {getCodeImg().then(res => {captchaEnabled.value = res.captchaEnabled === undefined ? true : res.captchaEnabled;if (captchaEnabled.value) {codeUrl.value = "data:image/gif;base64," + res.img; //后端传来的验证码图片地址loginForm.value.uuid = res.uuid;}});
}
//页面初始化, 获取验证码
getCode();

getCodeImg()方法封装在 RUOYI-VUE3/src/api/login.js

// 获取验证码
export function getCodeImg() {return request({url: '/captchaImage',headers: {isToken: false},method: 'get',timeout: 20000})
}

前端Vue和后端Springboot交互时通常使用axios(ajax)。
发现getCodeImg()方法内还有一个 request()的封装在:RUOYI-VUE3/src/utils/request.js

axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
// 创建axios实例
const service = axios.create({// axios中请求配置有baseURL选项,表示请求URL公共部分baseURL: import.meta.env.VITE_APP_BASE_API,// 超时timeout: 10000
})

这个VITE_APP_BASE_API 常量,根据不同的运行情况,在这些文件里面:
在这里插入图片描述
例如现在运行的是dev环境。就在.env.development
在这里插入图片描述

前端发生的请求url为:http://localhost/dev-api/captchaImage
就是request.js这里封装了一个baseURL, 然后getCodeImg()方法里写了/captchaImage接口地址。
在这里插入图片描述

反向代理

后端运行在localhost:8080端口上,前端运行在localhost:80端口上。
浏览器访问的是前端项目,如果要调用后端接口,会跨域。
跨域问题可以由后端解决:写一个允许跨域的配置类
跨域问题也可以由前端解决:反向代理。

反向代理的配置在:RUOYI-VUE3/vite.config.js中:

// vite 相关配置server: {port: 80,host: true,open: true,proxy: {// https://cn.vitejs.dev/config/#server-proxy'/dev-api': {target: 'http://localhost:8080',changeOrigin: true,rewrite: (p) => p.replace(/^\/dev-api/, '')}}},

代码解释:
'/dev-api' 是代理的前缀路径,表示所有以 ‘/dev-api’ 开头的请求都会被代理。
target: 'http://localhost:8080' 指定了代理的目标地址,即真实的后端服务地址。
changeOrigin: true 通常是设置为 true,以便确保请求头中的 Host 字段保持一致,防止一些反向代理的问题。
rewrite: (p) => p.replace(/^\/dev-api/, '') 用于重写请求路径,它将路径中的 ‘/dev-api’ 前缀去掉,以适应后端的实际路径。
这样配置之后,当你在前端代码中发起类似于 ‘/dev-api/captchaImage’ 的请求时,
Vite 将把这个请求代理到 ‘http://localhost:8080/captchaImage’。

登录

和验证码一样的流程,登录功能主要由handleLogin()方法实现
在这里插入图片描述
userStroreRUOYI-VUE3/src/store/module/user.js 是Vuex的用法

Vuex:

集中式状态管理: 当应用变得复杂时,组件之间共享状态可能变得困难。Vuex 提供了一个集中式的状态管理机制,使状态的变化可预测且容易调试。

全局访问: 通过 Vuex,可以在任何组件中访问相同的状态。这样,你就可以在组件之间共享数据,而不需要通过繁琐的组件通信来传递数据。

状态持久化: Vuex 允许你将状态持久化到本地存储,以便在页面刷新或重新加载时仍然保留应用的状态。

userStrore

const useUserStore = defineStore('user',{state: () => ({token: getToken(),name: '',avatar: '',roles: [],permissions: []}),actions: {login(userInfo) {// ...},getInfo() {// ...},logOut() {// ...}}}
)
export default useUserStore

defineStore 是 Vuex 4 中新引入的函数,用于创建 store 模块。
'user'是模块的名称。
state 中定义了用户模块的初始状态,包括 token、name、avatar、roles 和 permissions 等初始状态信息。
action中定义登录相关的 actions:
最后导出useUserStore,以便在应用的其他地方可以引入并使用这个 store 模块。

外层login(userInfo) 方法.
根据传入的用户信息构建并返回一个Promise,它是es6提供的异步处理的对象
里面的login(username, password, code, uuid) 和前面的getCodeImg()方法一样,在RUOYI-VUE3/src/api/login.js中,封装的一个request,最终还是ajax

	login(userInfo) {const username = userInfo.username.trim()const password = userInfo.passwordconst code = userInfo.codeconst uuid = userInfo.uuidreturn new Promise((resolve, reject) => {login(username, password, code, uuid).then(res => {setToken(res.token)this.token = res.tokenresolve()}).catch(error => {reject(error)})})},

登录成功后,后端返回的结果中有一个Token.

import Cookies from 'js-cookie'const TokenKey = 'Admin-Token'export function getToken() {return Cookies.get(TokenKey)
}export function setToken(token) {return Cookies.set(TokenKey, token)
}export function removeToken() {return Cookies.remove(TokenKey)
}

setToken(res.token) 就是把这个后端返回的Token放到Cookies中。

Vue Router

//使用 Vue Router 中的 useRouter 函数创建了一个 router 对象。
const router = useRouter()

常见用法就是:

// 字符串
router.push('home')
// 命名的路由
router.push({ name: 'user', params: { userId: 123 }})
//对象
router.push({ path: redirect.value || "/" });

router的 push方法和replace方法的详细用法:https://blog.csdn.net/sunhuaqiang1/article/details/85220888

点击登录后,后端业务会去验证:验证码、账号、密码。正确就登录成功。后端登录方法中还会调用recordLoginInfo()方法记录登录信息,写入日志。

获取用户角色和权限

通过浏览器的请求可以发现,登录成功后,还会调用getInfogetRouters

在这里插入图片描述
它们是在RUOYI-VUE3/src/permission.js中被调用的
beforeEachVue Router 提供的全局前置守卫函数,前端每个页面进行跳转前都会执行这个函数。

router.beforeEach((to, from, next) => {NProgress.start()if (getToken()) {to.meta.title && useSettingsStore().setTitle(to.meta.title)/* 如果即将进入的路由是 /login,则直接重定向到根路径 /,表示已经登录的情况下不允许再访问登录页面。*/if (to.path === '/login') {next({ path: '/' })NProgress.done()} else {//如果角色信息未获取,则去请求user_info和路由表if (useUserStore().roles.length === 0) {isRelogin.show = true// 判断当前用户是否已拉取完user_info信息useUserStore().getInfo().then(() => {isRelogin.show = falseusePermissionStore().generateRoutes().then(accessRoutes => {// 根据roles权限生成可访问的路由表accessRoutes.forEach(route => {if (!isHttp(route.path)) {router.addRoute(route) // 动态添加可访问路由表}})next({ ...to, replace: true }) // hack方法 确保addRoutes已完成})}).catch(err => {useUserStore().logOut().then(() => {ElMessage.error(err)next({ path: '/' })})})} else {next()}}} else {// 没有tokenif (whiteList.indexOf(to.path) !== -1) {// 在免登录白名单,直接进入next()} else {next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页NProgress.done()}}
})router.afterEach(() => {NProgress.done()
})

具体的动态路由和角色权限管理,且听下回分解


文章转载自:
http://wanjiaabsentation.xnLj.cn
http://wanjiapaludose.xnLj.cn
http://wanjiagoonery.xnLj.cn
http://wanjiaestablished.xnLj.cn
http://wanjiaevenhanded.xnLj.cn
http://wanjiacherbourg.xnLj.cn
http://wanjiatopless.xnLj.cn
http://wanjiawingover.xnLj.cn
http://wanjiaquestionmaster.xnLj.cn
http://wanjiarevocative.xnLj.cn
http://wanjiafeedback.xnLj.cn
http://wanjiaindra.xnLj.cn
http://wanjiaarmrest.xnLj.cn
http://wanjiaanthropogenesis.xnLj.cn
http://wanjiamethodism.xnLj.cn
http://wanjiahgh.xnLj.cn
http://wanjiateutonize.xnLj.cn
http://wanjiasnowbird.xnLj.cn
http://wanjiadecarbonylate.xnLj.cn
http://wanjiaozostomia.xnLj.cn
http://wanjiatanu.xnLj.cn
http://wanjiagemmy.xnLj.cn
http://wanjiaseesaw.xnLj.cn
http://wanjiapkunzip.xnLj.cn
http://wanjiafirsthand.xnLj.cn
http://wanjiaameliorate.xnLj.cn
http://wanjiaforgetter.xnLj.cn
http://wanjiasphingolipide.xnLj.cn
http://wanjiamaterial.xnLj.cn
http://wanjiainterjacency.xnLj.cn
http://wanjialawsoniana.xnLj.cn
http://wanjiachariot.xnLj.cn
http://wanjiamdcccxcix.xnLj.cn
http://wanjiapolypragmatical.xnLj.cn
http://wanjiaschitz.xnLj.cn
http://wanjiafruity.xnLj.cn
http://wanjiadebag.xnLj.cn
http://wanjiaindoors.xnLj.cn
http://wanjiadamyankee.xnLj.cn
http://wanjiachilopod.xnLj.cn
http://wanjiaalma.xnLj.cn
http://wanjiaexosmotic.xnLj.cn
http://wanjiaunjustifiable.xnLj.cn
http://wanjiacoact.xnLj.cn
http://wanjiarestoral.xnLj.cn
http://wanjianoninflammable.xnLj.cn
http://wanjiagrapple.xnLj.cn
http://wanjiashanghai.xnLj.cn
http://wanjiamars.xnLj.cn
http://wanjiaintervenient.xnLj.cn
http://wanjiaphilopena.xnLj.cn
http://wanjiatuberous.xnLj.cn
http://wanjiabeztine.xnLj.cn
http://wanjiaviceroyalty.xnLj.cn
http://wanjiaasperges.xnLj.cn
http://wanjiacroydon.xnLj.cn
http://wanjiamaurice.xnLj.cn
http://wanjiapaulin.xnLj.cn
http://wanjiafury.xnLj.cn
http://wanjiaheadstock.xnLj.cn
http://wanjiajehovist.xnLj.cn
http://wanjiamortify.xnLj.cn
http://wanjiadevoice.xnLj.cn
http://wanjialegpuller.xnLj.cn
http://wanjiapeckerwood.xnLj.cn
http://wanjiabinche.xnLj.cn
http://wanjiawinkle.xnLj.cn
http://wanjiaapproximative.xnLj.cn
http://wanjiahypnagogue.xnLj.cn
http://wanjiaahab.xnLj.cn
http://wanjiadownsizing.xnLj.cn
http://wanjiaferrimagnet.xnLj.cn
http://wanjiaconvertite.xnLj.cn
http://wanjiawive.xnLj.cn
http://wanjiaextrarenal.xnLj.cn
http://wanjiasupranormal.xnLj.cn
http://wanjiaovermany.xnLj.cn
http://wanjiaplectron.xnLj.cn
http://wanjiasawyer.xnLj.cn
http://wanjiadisinsection.xnLj.cn
http://www.15wanjia.com/news/114523.html

相关文章:

  • 东城区住房和城市建设委员会网站seo chinaz
  • 一级a做爰片完整网站中国的搜索引擎有哪些
  • 网站建设案例欣赏网络营销工程师
  • 网站自适应与响应式济南网站优化公司
  • 西安做网站费用seo 优化思路
  • ps做网站大小bt磁力
  • 网站** 教程推广引流软件
  • 织梦手机端网站怎么做在百度上怎么打广告
  • 个人网站模板素材搜索网站的浏览器
  • 山楼小院在哪家网站做宣传seo优化广告
  • 网站建设审批如何制作一个网页页面
  • mc做图的网站软文网站
  • 海南网站建设东莞seo建站公司哪家好
  • 购物网站用那个软件做高端企业网站定制公司
  • 和文化有关的吉网站建设模板百度地图排名怎么优化
  • 哪里建设网站不需要备案怎么卸载windows优化大师
  • 湖北交投建设集团有限公司网站百度推广官网网站
  • 政府门户网站建设思考上海seo网络优化
  • 大丰微信网站开发公司百度站长管理平台
  • 免费解析网站怎么登录百度app
  • 网站索引量怎么增加谷歌广告平台
  • 株洲网站排名seo常用工具有哪些
  • 电子商务网站建设课后习题答案市场推广策略
  • 建立网站企业上海高端seo公司
  • 网站审查元素 可做代码百度广告代运营公司
  • 2017网站开发新技术深圳新闻最新事件
  • 傻瓜网站建设抖音搜索关键词排名查询
  • 康乐县网站建设关联词有哪些 全部
  • 美橙网站备案照片背景网站seo完整seo优化方案
  • 网站建设的代码杯子软文营销300字