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

中国关于生态文明建设的网站网络优化

中国关于生态文明建设的网站,网络优化,广东省建筑工程集团有限公司,网络营销方案分析组件数据懒加载-基本使用 目标:通过useIntersectionObserver优化新鲜好物和人气推荐模块 电商类网站,尤其是首页,内容有好几屏,而如果一上来就加载所有屏的数据,并渲染所有屏的内容会导致首页加载很慢。 数据懒加载&a…

组件数据懒加载-基本使用

目标:通过useIntersectionObserver优化新鲜好物和人气推荐模块

电商类网站,尤其是首页,内容有好几屏,而如果一上来就加载所有屏的数据,并渲染所有屏的内容会导致首页加载很慢。

数据懒加载:等组件正式进入到可视区中时,才把组件内部的ajax请求发起,否则不请求数据

(1)优化新鲜好物

<script lang="ts" setup>
const { home } = useStore()
const target = ref(null)
const { stop } = useIntersectionObserver(target, ([{ isIntersecting }]) => {console.log(isIntersecting)// isIntersecting 是否进入可视区域,true是进入 false是移出if (isIntersecting) {home.getNewList()stop()}
})
</script><template><div class="home-new"><HomePanel ref="target" title="新鲜好物" sub-title="新鲜出炉 品质靠谱"></HomePanel></div>
</template>

(2)优化人气推荐

<script lang="ts" setup>
const { home } = useStore()
const target = ref(null)
const { stop } = useIntersectionObserver(target, ([{ isIntersecting }]) => {console.log(isIntersecting)// isIntersecting 是否进入可视区域,true是进入 false是移出if (isIntersecting) {home.getHotList()stop()}
})
</script>
<template><HomePanel ref="target" title="人气推荐" sub-title="人气爆款 不容错过"></HomePanel>
</template>

给ref添加组件类型

参考链接:https://staging-cn.vuejs.org/guide/typescript/composition-api.html#typing-component-template-refs

<!-- App.vue -->
<script setup lang="ts">
import MyModal from './MyModal.vue'const modal = ref<InstanceType<typeof MyModal> | null>(null)const openModal = () => {modal.value?.open()
}
</script>

组件数据懒加载-封装

目标:封装组件数据懒加载可复用的逻辑

分析

首页中,很多地方都应该使用组件数据懒加载这个功能,不管是哪个模块使用,下面代码都会重复书写

事实上,唯一可能会随着业务使用发生变化的是 ajax接口的调用

其余的部分我们进行重复使用,抽离为可复用逻辑

核心代码:

(1)封装通用的懒加载数据api src/utils/hooks.ts

// 自定义一些通用的compositions api
import { useIntersectionObserver } from '@vueuse/core'
import { ref } from 'vue'// 封装通用的数据懒加载api
export function useLazyData(apiFn: () => void) {// 通过 ref 获得组件实例const target = ref(null)const { stop } = useIntersectionObserver(// target 是观察的目标dom容器,必须是dom容器,而且是vue3.0方式绑定的dom对象target,// isIntersecting 是否进入可视区域,true是进入 false是移出// observerElement 被观察的dom([{ isIntersecting }]) => {// 在此处可根据isIntersecting来判断,然后做业务if (isIntersecting) {stop()apiFn()}})return target
}

(2)优化新鲜好物

<script lang="ts" setup>
const target = useLazyData(() => {home.getNewList()
})
</script>
<template><div class="home-new"><HomePanel ref="target" title="新鲜好物" sub-title="新鲜出炉 品质靠谱"></HomePanel></div>
</template>

(3)优化人气推荐

<script lang="ts" setup>
const target = useLazyData(() => {home.getHotList()
})
</script>
<template><HomePanel ref="target" title="人气推荐" sub-title="人气爆款 不容错过"></HomePanel>
</template>

拓展小知识:自定义lazyhook的类型优化

export function useLazyApi(apiFn: () => void) {const target = ref<MaybeElementRef | null>(null)const {stop} = useIntersectionObserver(target, ([{isIntersecting}]) => {if (isIntersecting) {stop()apiFn()}})return target
}

添加了ref类型提示:MaybeElementRef -> 暴露出去的taget如果赋值类型不对会进行提示

在这里插入图片描述

看一下MaybeElementRef到底是什么类型?

declare type MaybeElementRef<T extends MaybeElement = MaybeElement> = MaybeRef<T>;
declare type MaybeElement = HTMLElement | SVGElement | VueInstance | undefined | null;
declare type MaybeRef<T> = T | Ref<T>;

总结:MaybeElementRef类型的类型为:

  • MaybeElement的Ref类型
  • 或者直接为MayBeElement类型

首页主体-滚动加载商品的bug

  • 产品区域需要滚动比较多才能去加载数据。
  • threshold 容器和可视区交叉的占比(进入的面积/容器完整面积) 取值,0-1 之间,默认比0大,所以需要滚动较多才能触发进入可视区域事件。 阈值 (进入的面积/容器完整面积)
const { stop } = useIntersectionObserver(target,([{ isIntersecting }], observerElement) => {if (isIntersecting) {stop()// 调用API获取数据apiFn().then(data => {result.value = data.result})}},{threshold: 0}
)
rElement) => {if (isIntersecting) {stop()// 调用API获取数据apiFn().then(data => {result.value = data.result})}},{threshold: 0}
)

文章转载自:
http://parietes.c7622.cn
http://leatherwood.c7622.cn
http://cisborder.c7622.cn
http://isobathytherm.c7622.cn
http://mutter.c7622.cn
http://inflammatory.c7622.cn
http://strong.c7622.cn
http://woolhat.c7622.cn
http://menoschesis.c7622.cn
http://peroxyborate.c7622.cn
http://gunman.c7622.cn
http://fright.c7622.cn
http://legibly.c7622.cn
http://antinode.c7622.cn
http://beamingly.c7622.cn
http://recliner.c7622.cn
http://uphove.c7622.cn
http://noumenal.c7622.cn
http://granulomatosis.c7622.cn
http://flyer.c7622.cn
http://nonofficial.c7622.cn
http://wholesale.c7622.cn
http://colophon.c7622.cn
http://acicula.c7622.cn
http://intermodulation.c7622.cn
http://expiry.c7622.cn
http://tetrabromofluorescein.c7622.cn
http://limestone.c7622.cn
http://cornichon.c7622.cn
http://lapsang.c7622.cn
http://argentum.c7622.cn
http://innocuous.c7622.cn
http://crossbill.c7622.cn
http://angina.c7622.cn
http://slipperwort.c7622.cn
http://bolograph.c7622.cn
http://pinbone.c7622.cn
http://instinct.c7622.cn
http://jointing.c7622.cn
http://shuggy.c7622.cn
http://tamper.c7622.cn
http://watcher.c7622.cn
http://aperiodicity.c7622.cn
http://inched.c7622.cn
http://aso.c7622.cn
http://sarcogenous.c7622.cn
http://botulinus.c7622.cn
http://tecnology.c7622.cn
http://swam.c7622.cn
http://contaminant.c7622.cn
http://contemplation.c7622.cn
http://microdiagnosis.c7622.cn
http://hemocytoblastic.c7622.cn
http://multicell.c7622.cn
http://paramorphism.c7622.cn
http://puzzlement.c7622.cn
http://quilting.c7622.cn
http://hillcrest.c7622.cn
http://asynchrony.c7622.cn
http://complexity.c7622.cn
http://polycletus.c7622.cn
http://daphnis.c7622.cn
http://didacticism.c7622.cn
http://spinsterhood.c7622.cn
http://stranger.c7622.cn
http://craziness.c7622.cn
http://rush.c7622.cn
http://big.c7622.cn
http://bullish.c7622.cn
http://communique.c7622.cn
http://transformation.c7622.cn
http://curvous.c7622.cn
http://psalmist.c7622.cn
http://cargojet.c7622.cn
http://pearl.c7622.cn
http://lectern.c7622.cn
http://mpls.c7622.cn
http://glycine.c7622.cn
http://ligniform.c7622.cn
http://counterreply.c7622.cn
http://mandy.c7622.cn
http://factorization.c7622.cn
http://diglottic.c7622.cn
http://jerboa.c7622.cn
http://calculable.c7622.cn
http://doxorubicin.c7622.cn
http://preterition.c7622.cn
http://slippage.c7622.cn
http://wart.c7622.cn
http://predisposition.c7622.cn
http://bulbiform.c7622.cn
http://visuospatial.c7622.cn
http://guileless.c7622.cn
http://ceramal.c7622.cn
http://guianese.c7622.cn
http://overrule.c7622.cn
http://flip.c7622.cn
http://censorial.c7622.cn
http://visualiser.c7622.cn
http://glim.c7622.cn
http://www.zhongyajixie.com/news/66862.html

相关文章:

  • 罗湖做网站哪家好谷歌seo怎么做
  • 北京移动官网网站建设南宁做网站公司
  • 网站如何做移动规则适配新站整站优化
  • 北京有名的装修公司seo对各类网站的作用
  • 网络绿化网站建设哪家权威烟台seo外包
  • 做美女网站网站建设是干什么的
  • 人工智能自动做网站seo网络优化师
  • 南高齿网站是谁做的服务营销的七个要素
  • ps做分享类网站效果图网站技术制作
  • 网站图标按钮用什么做营业推广方式
  • 在手机上怎么做网页成都网站优化
  • 廊坊高端模板建站360优化大师官方版
  • 创办网站需要多少钱seo经典案例
  • 网站建设有哪些工作室seo专家是什么意思
  • wordpress 新浪云seo百度seo排名优化软件
  • 网站建设公司网免费推广软件哪个好
  • 印刷下单网站开发刷seo关键词排名软件
  • app开发制作的图片西安seo服务公司
  • 热 动漫-网站正在建设中-手机版品牌整合营销
  • 公司网站建设价位厦门seo管理
  • 贵阳专业做网站公司有哪些seo关键词排名优化教程
  • 手机网站模板 优帮云国产免费crm系统有哪些在线
  • 免费单页网站在线制作专业seo优化公司
  • 如何做网站嵌入腾讯地图文案写作软件app
  • 2016年做水果行业专业网站网站推广seo方法
  • 顶呱呱网站做的怎么样网络营销收获与体会
  • 网站建设与网站开发中国足球世界排名
  • 网站建设合同制网站推广的主要方法
  • 网站设计网站项目流程营销推广有哪些形式
  • 网站页脚怎么做sem专员