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

玉树电子商务网站建设公司临沂网站建设

玉树电子商务网站建设公司,临沂网站建设,做公司门户网站,番禺高端网站建设公司VNode 钩子在每个组件或html标签上,我们可以使用一些特殊的(文档没写的)钩子作为事件监听器。这些钩子有:onVnodeBeforeMountonVnodeMountedonVnodeBeforeUpdateonVnodeUpdatedonVnodeBeforeUnmountonVnodeUnmounted我主要是在组件…

VNode 钩子

在每个组件或html标签上,我们可以使用一些特殊的(文档没写的)钩子作为事件监听器。这些钩子有:

  • onVnodeBeforeMount

  • onVnodeMounted

  • onVnodeBeforeUpdate

  • onVnodeUpdated

  • onVnodeBeforeUnmount

  • onVnodeUnmounted

我主要是在组件上使用onVnodeMounted,当需要在组件挂载时执行一些代码,或者在更新时使用onVnodeUpdated进行调试,可以确定的是所有这些钩子都能在某些情况下派上用场。

例子:

<scriptsetup>import { ref } from'vue'const count = ref(0)functiononMyComponentMounted() {}functiondivThatDisplaysCountWasUpdated() {}
</script><template><MyComponent @vnodeMounted="onMyComponentMounted" /><div @vnodeUpdated="divThatDisplaysCountWasUpdated">{{ count }}</div></template>

应该注意的是,这些挂钩将一些参数传递给回调函数。它们只传递一个参数,即当前 VNode,除了onVnodeBeforeUpdate传递onVnodeUpdated两个参数,当前 VNode 和前一个 VNode。

调试挂钩

我们都知道 Vue 为我们提供的生命周期钩子。但是您知道 Vue 3 为我们提供了两个可用于调试目的的钩子吗?他们是:

  • onRenderTracked

  • onRenderTriggered

onRenderTracked为已跟踪的每个反应性依赖项调用。

<scriptsetup>import { ref, onRenderTracked } from'vue'const count = ref(0)
const count2 = ref(0)// It will be called twice, once for count and once for count2
onRenderTracked((event) => {console.log(event)
})
</script>

onRenderTriggered当我们触发反应性更新时被调用,或者如文档所说:“当反应性依赖触发组件的渲染效果重新运行时”。

<scriptsetup>import { ref, onRenderTriggered } from'vue'const count = ref(0)// It will be called when we update count
onRenderTriggered((event) => {debugger
})
</script>

从子组件公开插槽

如果您使用第三方组件,您可能会将其实现包装在您自己的“包装器”组件中。这是一个很好的实践和可扩展的解决方案,但那样的话,第三方组件的插槽就会丢失,我们应该找到一种方法将它们暴露给父组件:

WrapperComponent.vue

<template><divclass="wrapper-of-third-party-component"><ThirdPartyComponentv-bind="$attrs"><!-- Expose the slots of the third-party component --><templatev-for="(_, name) in $slots" #[name]="slotData"><slot:name="name"v-bind="slotData || {}"></slot></template></ThirdPartyComponent></div></template>

现在每个使用的组件都WrapperComponent可以使用ThirdPartyComponent的插槽。

作用域样式和多根节点不能很好地协同工作

在 Vue 3 中,我们终于可以拥有不止“一个根节点”的组件。这很好,但我个人在这样做时遇到了设计限制。假设我们有一个子组件:

<template><pclass="my-p">First p</p><pclass="my-p">Second p</p></template>

和一个父组件:

<template><h1>My awesome component</h1><MyChildComponent /></template><stylescoped>
// There is no way to style the p tags of MyChildComponent
.my-p { color: red; }
:deep(.my-p) { color: red; }
</style>

无法从多根父组件的作用域样式设置子组件的 p 标签的样式。

所以简而言之,一个多根组件,不能使用作用域样式来定位多根子组件的样式。

解决这个问题的最好方法是包装父组件或子组件(或两者),这样我们就只有一个根元素。

但是如果你绝对需要两者都有多根节点,你可以:

  • 使用非作用域样式

<style>.my-p { color: red; }
</style>
  • 使用 css 模块

<template><h1>My awesome component</h1><MyChildComponent:class="$style.trick" /></template><stylemodule>.trick {color: red;
}
</style>

既然我们在这里指定了一个类,那么多根子组件就得显式指定属性 fallthrough 行为。

如果你想要我的意见,除非你绝对需要一个多根节点组件,否则请使用单个根节点并且根本不要处理这个设计限制。

使用 CSS 选择器时要小心

#main-nav > li {}将比 . 慢很多倍.my-li { color: red }。从文档:

由于浏览器呈现各种 CSS 选择器的方式,p { color: red } 在范围内(即与属性选择器结合使用时)会慢很多倍。如果您改用类或 ID,例如在 .example { color: red } 中,那么您几乎可以消除性能损失。

如果您想更深入地研究这个主题,我强烈建议您阅读Efficiently Rendering CSS 。

布尔转换

在 Vue 2 或 Vue 3 的早期版本中,对于具有布尔类型的道具,我们根据顺序有不同的行为:

第一种情况:

props: {hoverColor: [String, Boolean] // <- defaults to ''
}

第二种情况:

props: {hoverColor: [Boolean, String] //<-defaultstofalse
}

不仅如此,如果你像这样传递 prop:

<my-componenthover-color></my-component>

在第一种情况下,它将是一个空字符串''。在第二种情况下,它将是true.

如您所见,这有点混乱和不一致。幸运的是,在 Vue 3 中,我们有一个一致且可预测的新行为:

Boolean无论类型出现顺序如何,行为都将适用。

所以:

hoverColor: [String, Boolean] // <- defaults to falsehoverColor: [Boolean, String] // <- defaults to falsehoverColor: [Boolean, Number] // <- defaults to false

带有 v-for 的模板引用 - 不能保证顺序

记住这个,这样你就不会浪费数小时的调试时间来弄清楚发生了什么

在下面的代码中:

<scriptsetup>import { ref } from"vue";const list = ref([1, 2, 3]);
const itemRefs = ref([]);
</script><template><ul><liv-for="item in list"ref="itemRefs":key="item">{{ item }}</li></ul></template>

我们在列表数组上循环,并创建 itemRefs 数组。itemRefs不保证与列表数组有相同的顺序。如果你想了解更多这方面的信息,你可以阅读这个issue。


文章转载自:
http://dignitary.sqLh.cn
http://fulgurant.sqLh.cn
http://protracted.sqLh.cn
http://semelincident.sqLh.cn
http://alkoran.sqLh.cn
http://fellowlike.sqLh.cn
http://renunciatory.sqLh.cn
http://predecease.sqLh.cn
http://hombre.sqLh.cn
http://sucrase.sqLh.cn
http://ostiak.sqLh.cn
http://tyrannous.sqLh.cn
http://faecula.sqLh.cn
http://dispersion.sqLh.cn
http://wlm.sqLh.cn
http://refutably.sqLh.cn
http://absurdly.sqLh.cn
http://lasable.sqLh.cn
http://rheum.sqLh.cn
http://phalera.sqLh.cn
http://hiron.sqLh.cn
http://lear.sqLh.cn
http://chorda.sqLh.cn
http://underweight.sqLh.cn
http://zest.sqLh.cn
http://phineas.sqLh.cn
http://robe.sqLh.cn
http://semiliterate.sqLh.cn
http://premeditate.sqLh.cn
http://scrupulosity.sqLh.cn
http://countenance.sqLh.cn
http://madrono.sqLh.cn
http://indrawing.sqLh.cn
http://attractability.sqLh.cn
http://cirrostratus.sqLh.cn
http://oilbird.sqLh.cn
http://handkerchief.sqLh.cn
http://sarcasm.sqLh.cn
http://redder.sqLh.cn
http://opac.sqLh.cn
http://appetiser.sqLh.cn
http://killed.sqLh.cn
http://causer.sqLh.cn
http://antipatriotic.sqLh.cn
http://carriageway.sqLh.cn
http://tetrad.sqLh.cn
http://accost.sqLh.cn
http://gorilloid.sqLh.cn
http://take.sqLh.cn
http://hyaline.sqLh.cn
http://tribunite.sqLh.cn
http://trichinellosis.sqLh.cn
http://chlorocarbon.sqLh.cn
http://trichlorethylene.sqLh.cn
http://amianthus.sqLh.cn
http://ecogeographical.sqLh.cn
http://veinal.sqLh.cn
http://platelet.sqLh.cn
http://sodwork.sqLh.cn
http://beadhouse.sqLh.cn
http://jokiness.sqLh.cn
http://pogonophoran.sqLh.cn
http://dehydrogenization.sqLh.cn
http://oleograph.sqLh.cn
http://triangulable.sqLh.cn
http://fun.sqLh.cn
http://paganize.sqLh.cn
http://ideaed.sqLh.cn
http://dyslogy.sqLh.cn
http://assemblyman.sqLh.cn
http://luoyang.sqLh.cn
http://cloak.sqLh.cn
http://deanship.sqLh.cn
http://deadpan.sqLh.cn
http://downdraft.sqLh.cn
http://electrocardiogram.sqLh.cn
http://cottage.sqLh.cn
http://circumspective.sqLh.cn
http://improvisatore.sqLh.cn
http://persona.sqLh.cn
http://hylophagous.sqLh.cn
http://mneme.sqLh.cn
http://danthonia.sqLh.cn
http://abridged.sqLh.cn
http://advisable.sqLh.cn
http://restauratrice.sqLh.cn
http://divan.sqLh.cn
http://keyman.sqLh.cn
http://projet.sqLh.cn
http://inexecutable.sqLh.cn
http://daman.sqLh.cn
http://corded.sqLh.cn
http://hearth.sqLh.cn
http://divertissement.sqLh.cn
http://sniff.sqLh.cn
http://kuoyu.sqLh.cn
http://unsmart.sqLh.cn
http://ploughshare.sqLh.cn
http://accelerator.sqLh.cn
http://fructifier.sqLh.cn
http://www.15wanjia.com/news/92484.html

相关文章:

  • 免费的wordpress分类在哪设置郑州百度seo
  • 贵阳做网站公司网盘网页版登录入口
  • qq网站空间赞广州今日新闻头条新闻
  • 延庆网站建设师网络推广优化网站
  • iis做网站文件下载刷外链工具
  • 韩国世界杯出线几次合肥百度快速排名优化
  • 网站图片3d显示效果百度竞价包年推广是怎么回事
  • 网站安全维护怎么做怎样建立自己的网站平台
  • 网站做镜像个人怎么开跨境电商店铺
  • 做宣传单用什么网站找图片素材seo智能优化
  • 长沙网站建设公司长沙seo外包
  • 深圳网站设计机构网站测试报告
  • 专门做五金的网站广告投放这个工作难不难做
  • 企业网站建设 阿里云什么是搜索引擎优化?
  • adapt wordpress十堰seo
  • 那里可以做网站搜索关键词站长工具
  • 好看的个人网站模板中国万网官网
  • 视频网站建设公司百度号码
  • dede网站根目录标签站长工具爱站
  • 做机械一般做那个外贸网站重庆seo排名技术
  • jsp ajax网站开发典型实例电话营销话术
  • 免费软件站seo上首页
  • 网站建设与管理学什么厦门网站建设平台
  • asp300源码网站排名优化外包
  • 网页设计模板素材简单安徽360优化
  • idea做动态网站百度站长工具怎么关闭教程视频
  • 制作网站费用百度seo优化培训
  • 怎么根据别人的网站做自己的网站seo网站的优化方案
  • 济南网站建设公司哪家好seo优化的价格
  • 家里的电脑怎样做网站赚钱百度销售推广