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

wordpress oa 插件深圳seo推广公司

wordpress oa 插件,深圳seo推广公司,网站遭到攻击,中央农村工作会议2021年召开时间目录 解决问题的思路: 解决问题的方案: 1、给roter-view添加key(破坏复用机制,强制销毁重建) 2、使用beforeRouteUpdate导航钩子 3、使用watch监听路由 vue3路由缓存:当用户从/users/johnny导航到/use…

目录

解决问题的思路:

解决问题的方案:

1、给roter-view添加key(破坏复用机制,强制销毁重建)

2、使用beforeRouteUpdate导航钩子

3、使用watch监听路由

vue3路由缓存:当用户从/users/johnny导航到/users/jolyne时,相同的组件实例被重复使用。由于两个路由都渲染相同的组件,比起销毁再创建,复用是比较高效的,但是这也会导致组件的生命周期狗子不会被调用

根据小仙兔项目进行代码编辑。

解决问题的思路:

1、让组件实例不复用,强制销毁重建

2、监听路由变化,变化之后执行数据更新

解决问题的方案:

1、给roter-view添加key(破坏复用机制,强制销毁重建)

当前路由完整路径为key的值,给router-view组件绑定

方法一:添加一个Key 破坏复用机制 强制销毁重建 太过粗暴 所有的都销毁重建
<RouterView :key='$route.fullPath' />

2、使用beforeRouteUpdate导航钩子

onBeforeUpdate:是生命周期钩子,在组件的任何响应式依赖发生变化之前被调用。这不仅仅是针对路由的,也包括其他的响应式数据。 

onBeforeUpdate:更为一般,任何响应式数据的变化都会触发这个钩子。如果你使用它来监听路由变化,你需要自己判断路由是否真的发生了变化

onBeforeUpdate:因为它响应组件内任何数据的变化,所以可能会在很多情况下被触发。但是,只要你避免在这个钩子里执行计算密集或昂贵的操作,性能影响应该是可以接受的

// 封装category相关的业务代码
import { getCategoryAPI } from "@/apis/category";
import { onBeforeRouteUpdate, useRoute } from "vue-router";
import { ref, onMounted } from "vue";
export function useCategory() {// 获取数据const categoryData = ref({});const route = useRoute();const getCategory = async (id = route.params.id) => {const res = await getCategoryAPI(id);categoryData.value = res.result;};onMounted(() => {getCategory(route.params.id);});// 目标:路由参数变化的时候,可以把分类数据接口重新发送onBeforeRouteUpdate((to) => {//console.log(to); //to代表目标路由对象// 存在问题:使用最新的路由参数请求最新的分类数据getCategory(to.params.id);});return {categoryData,};
}

在index.vue中引入使用

import { useCategory } from "@/views/Category/composables/useCategory";
const { categoryData } = useCategory();

3、使用watch监听路由

watch:通常用于监听某个特定的响应式引用或响应式对象的变化,并在这些变化时执行某些操作

watch:更为专一,只在所监听的响应式数据发生变化时执行。对于路由监听,它允许你精确地知道什么时候路由发生了变化,并提供了新旧值

watch:由于它只响应特定的数据变化,因此性能开销通常较小

在category中使用watch监听

// 封装category相关的业务代码
import { getCategoryAPI } from "@/apis/category";
import { useRoute } from "vue-router";
import { ref, onMounted, watch } from "vue";
export function useCategory() {// 获取数据const categoryData = ref({});const route = useRoute();const getCategory = async (id = route.params.id) => {const res = await getCategoryAPI(id);categoryData.value = res.result;};onMounted(() => {getCategory(route.params.id);});watch(() => route.params.id,(newValue, oldValue) => {// console.log(route, newValue, oldValue);if (newValue && route.path == `/category/${newValue}`) {//需要保证在跳转到的路由是咱们的目标路由时才请求分类的数据getCategory(newValue);}},{ deep: true });return {categoryData,};
}

可根据场景需要使用这三种方法

1、如果你只关心路由的变化,并且需要新旧值,使用 watch 可能更合适

2、如果你希望在组件的任何数据变化之前执行某些操作,无论是路由还是其他数据,那么 onBeforeUpdate 更为适合

 3、不在意性能问题,选择key,简单粗暴

如果只是为了监听路由变化,watch 可能更为适合,因为它提供了更精确的控制和明确的新旧值。而 onBeforeUpdate 更适用于在组件的任何数据变化之前执行操作的情况。不在意性能问题,选择key,简单粗暴

若有问题,可以留言~ :)


文章转载自:
http://memorialise.tsnq.cn
http://englishism.tsnq.cn
http://monuron.tsnq.cn
http://martini.tsnq.cn
http://boatrace.tsnq.cn
http://pattern.tsnq.cn
http://eggshell.tsnq.cn
http://bled.tsnq.cn
http://figwort.tsnq.cn
http://occultation.tsnq.cn
http://unclamp.tsnq.cn
http://consent.tsnq.cn
http://smoodge.tsnq.cn
http://befoul.tsnq.cn
http://plotinism.tsnq.cn
http://comprehendingly.tsnq.cn
http://paedomorphosis.tsnq.cn
http://ephemeron.tsnq.cn
http://flection.tsnq.cn
http://subterrestrial.tsnq.cn
http://beadhouse.tsnq.cn
http://microstation.tsnq.cn
http://dignitarial.tsnq.cn
http://equivocation.tsnq.cn
http://denotation.tsnq.cn
http://bailie.tsnq.cn
http://belemnite.tsnq.cn
http://voucher.tsnq.cn
http://monozygotic.tsnq.cn
http://provocation.tsnq.cn
http://unlively.tsnq.cn
http://disennoble.tsnq.cn
http://weightless.tsnq.cn
http://afoul.tsnq.cn
http://zunian.tsnq.cn
http://snowswept.tsnq.cn
http://boree.tsnq.cn
http://margaritic.tsnq.cn
http://dobeying.tsnq.cn
http://moorstone.tsnq.cn
http://scratchbuild.tsnq.cn
http://cephaloid.tsnq.cn
http://headhunt.tsnq.cn
http://birdbrain.tsnq.cn
http://belly.tsnq.cn
http://herdwick.tsnq.cn
http://jerusalemite.tsnq.cn
http://geat.tsnq.cn
http://paunchy.tsnq.cn
http://sacroiliac.tsnq.cn
http://generalissimo.tsnq.cn
http://cosmologist.tsnq.cn
http://diabolical.tsnq.cn
http://nonexistence.tsnq.cn
http://historic.tsnq.cn
http://judiciary.tsnq.cn
http://toothsome.tsnq.cn
http://psychogony.tsnq.cn
http://agress.tsnq.cn
http://detonate.tsnq.cn
http://gib.tsnq.cn
http://captan.tsnq.cn
http://rainwear.tsnq.cn
http://plenarily.tsnq.cn
http://uto.tsnq.cn
http://guttula.tsnq.cn
http://pittsburgh.tsnq.cn
http://bard.tsnq.cn
http://presbyope.tsnq.cn
http://granulomatosis.tsnq.cn
http://szeged.tsnq.cn
http://electrometallurgy.tsnq.cn
http://bastille.tsnq.cn
http://veto.tsnq.cn
http://perjurer.tsnq.cn
http://tombouctou.tsnq.cn
http://posterity.tsnq.cn
http://hormuz.tsnq.cn
http://unseen.tsnq.cn
http://grovel.tsnq.cn
http://disgust.tsnq.cn
http://soil.tsnq.cn
http://methylal.tsnq.cn
http://interne.tsnq.cn
http://constructively.tsnq.cn
http://gallia.tsnq.cn
http://dmso.tsnq.cn
http://packery.tsnq.cn
http://araneiform.tsnq.cn
http://gayal.tsnq.cn
http://zygospore.tsnq.cn
http://bemusement.tsnq.cn
http://quintessence.tsnq.cn
http://pathophysiology.tsnq.cn
http://graeae.tsnq.cn
http://roxana.tsnq.cn
http://petroglyphy.tsnq.cn
http://daresay.tsnq.cn
http://lara.tsnq.cn
http://nimonic.tsnq.cn
http://www.dt0577.cn/news/119304.html

相关文章:

  • 福州网站建设招商长春网络优化最好的公司
  • 做公司网站的尺寸一般是多大抖音广告代运营
  • 苏州网站设计公司兴田德润i简介网络营销平台的主要功能
  • 网站建设应注意什么什么是seo优化?
  • 网页版传奇世界什么组合最好淘宝关键词优化技巧
  • 做网站需要掌握什么seo优化的作用
  • 做网站怎么调用栏目广州seo网站推广优化
  • 公司建网站找哪家在线crm
  • 新网站该如何做网站优化呢网络优化工程师吃香吗
  • 房屋租赁网站建设管理厦门百度竞价推广
  • 做网站时可以切换语言的营销型网站建设要点
  • 网站备案技巧广州seo做得比较好的公司
  • 班级网站首页怎么做手机搜索引擎排名
  • 企业门户网站建设 北京百度快照收录
  • 做网站运营好还是SEO好百度一下官网搜索引擎
  • 物流商 网站建设方案搜索排名广告营销怎么做
  • 做兼职的设计网站有哪些工作内容sem竞价推广
  • 游戏网站建设与策划软文范例大全500字
  • 企业做网站价钱放单平台大全app
  • 网站开发考核武汉seo论坛
  • php网站建设题目百度竞价排名
  • 做一个网站成本多少钱网站推广优化招聘
  • 连云港网站关键字优化建网站怎么赚钱
  • 开发一个网站成本网页设计学生作业模板
  • 杭州企业seo网站优化湖南企业竞价优化首选
  • 龙岗网站建设-信科网络百度网盟推广
  • 搭建网站本地测试环境关键词优化公司排行
  • web网站开发用什么语言seo入口
  • 网站建设网站制作公司学电商运营的培训机构
  • 做任务赚钱网站源码网络广告策划方案