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

flash网站开发工具seo月薪

flash网站开发工具,seo月薪,destoon 网站搬家,外贸网站建设哪里实惠文章目录 一、前言二、实现三、优化四、总结五、最后 一、前言 在开发中&#xff0c;你经常会遇到这么一种情况&#xff1a;根据条件动态地切换某个组件&#xff0c;或动态地选择渲染某个组件。 Vue 提供了另外一个内置的组件 <component> 和 is 特性&#xff0c;可以更…

文章目录

  • 一、前言
  • 二、实现
  • 三、优化
  • 四、总结
  • 五、最后

一、前言

在开发中,你经常会遇到这么一种情况:根据条件动态地切换某个组件,或动态地选择渲染某个组件。 Vue 提供了另外一个内置的组件 <component>is 特性,可以更好地实现动态组件。

二、实现

首先来看看<component>is 的基本使用,首先定义三个普通组件ABC

<template><div>组件 A</div>
</template>
<script>export default {}
</script><template><div>组件 B</div>
</template>
<script>export default {}
</script><template><div>组件 C</div>
</template>
<script>export default {}
</script>

然后在父组件中导入这 3 个组件,并动态切换:

<template><div><button @click="handleChange('A')">显示 A 组件</button><button @click="handleChange('B')">显示 B 组件</button><button @click="handleChange('C')">显示 C 组件</button><component :is="component"></component></div>
</template>
<script>import componentA from '../components/a.vue';import componentB from '../components/b.vue';import componentC from '../components/c.vue';export default {data () {return {component: componentA}},methods: {handleChange (component) {if (component === 'A') {this.component = componentA;} else if (component === 'B') {this.component = componentB;} else if (component === 'C') {this.component = componentC;}}}}
</script>

这里的 is 动态绑定的是一个组件对象Object),它直接指向 a / b / c 三个组件中的一个。除了直接绑定一个 Object,还可以是一个 String,比如标签名、组件名

下面的这个组件,将原生的按钮 button 进行了封装,如果传入了 prop: to,那它会渲染为一个链接地址 <a> 标签,用于打开这个,如果没有传入 to,就当作普通 button 使用。

<template><component :is="tagName" v-bind="tagProps"><slot></slot></component>
</template><script>
export default {props: {// 链接地址to: {type: String,default: ''},// 链接打开方式,如 _blanktarget: {type: String,default: '_self'}},computed: {// 动态渲染不同的标签tagName() {return this.to === '' ? 'button' : 'a'},// 如果是链接,把这些属性都绑定在 component 上tagProps() {let props = {}if (this.to) {props = {target: this.target,href: this.to}}return props}}
}
</script>

使用组件:

<template>
<div><i-button>普通按钮</i-button><br /><i-button to="https://juejin.cn">链接按钮</i-button><br /><i-button to="https://juejin.cn" target="_blank">新窗口打开链接按钮</i-button>
</div>
</template>
<script>
import iButton from './components/button.vue'export default {
components: { iButton }
}
</script>

最终会渲染出一个原生的 <button> 按钮和两个原生的链接 <a>,且第二个点击会在新窗口中打开链接,如图:

img

i-button 组件中的 <component> is 绑定的就是一个标签名称 button / a,并且通过 v-bind 将一些额外的属性全部绑定到了 <component> 上。

三、优化

再回到第一个 a / b / c 组件切换的示例,如果这类的组件,频繁切换,事实上组件是会重新渲染的。

现在在组件 A 里加两个生命周期 mounted, beforeDestroy。只要切换到 A 组件,mounted 就会触发一次,切换到其它组件,beforeDestroy 也会触发一次,说明组件再重新渲染,这样有可能导致性能问题。

为了避免组件的重复渲染,可以在 <component> 外层套一个 Vue.js 内置的 <keep-alive> 组件,这样组件就会被缓存起来:

<keep-alive><component :is="component"></component>
</keep-alive>

这时,只有 mounted 触发了,如果不离开当前页面,切换到其它组件,beforeDestroy 不会被触发,说明组件已经被缓存了。

四、总结

动态组件广泛应用于灵活渲染组件的场景,根据某种条件来渲染不同的组件,搭配<keep-alive>可以避免组件频繁的创建与销毁。

源码地址可点击【跳转】访问,在线调试代码

五、最后

本人每篇文章都是一字一句码出来,希望对大家有所帮助,多提提意见。顺手来个三连击,点赞👍收藏💖关注✨,一起加油☕


文章转载自:
http://dinncoretention.ssfq.cn
http://dinncothose.ssfq.cn
http://dinncorsp.ssfq.cn
http://dinnconappe.ssfq.cn
http://dinncoexpeditiously.ssfq.cn
http://dinncomonial.ssfq.cn
http://dinncopairage.ssfq.cn
http://dinncoretrogression.ssfq.cn
http://dinncoliebfraumilch.ssfq.cn
http://dinncounliquefied.ssfq.cn
http://dinncosnobling.ssfq.cn
http://dinncokansan.ssfq.cn
http://dinncochaussee.ssfq.cn
http://dinncochiz.ssfq.cn
http://dinncoboatage.ssfq.cn
http://dinnconeodoxy.ssfq.cn
http://dinncowrestle.ssfq.cn
http://dinncometayer.ssfq.cn
http://dinncodali.ssfq.cn
http://dinncogock.ssfq.cn
http://dinncobelizean.ssfq.cn
http://dinncodeformable.ssfq.cn
http://dinncocautiously.ssfq.cn
http://dinncogunner.ssfq.cn
http://dinncoservomechanism.ssfq.cn
http://dinncothomson.ssfq.cn
http://dinncocaponier.ssfq.cn
http://dinncoahasuerus.ssfq.cn
http://dinncodysplasia.ssfq.cn
http://dinncodementia.ssfq.cn
http://dinncoulvaespinel.ssfq.cn
http://dinncobluegill.ssfq.cn
http://dinncosynchronizer.ssfq.cn
http://dinncogastronomist.ssfq.cn
http://dinncoclackmannanshire.ssfq.cn
http://dinncocrenulated.ssfq.cn
http://dinncoscantily.ssfq.cn
http://dinncothwartwise.ssfq.cn
http://dinncolaika.ssfq.cn
http://dinncoimparkation.ssfq.cn
http://dinncoscottish.ssfq.cn
http://dinncorunning.ssfq.cn
http://dinncosubmergible.ssfq.cn
http://dinnconigaragua.ssfq.cn
http://dinncopaulinize.ssfq.cn
http://dinncopolarisability.ssfq.cn
http://dinncoubiquitously.ssfq.cn
http://dinncoentomophily.ssfq.cn
http://dinncofibreboard.ssfq.cn
http://dinncomultiphoton.ssfq.cn
http://dinncoheliolatry.ssfq.cn
http://dinncopsychologize.ssfq.cn
http://dinncooutwear.ssfq.cn
http://dinncosubulate.ssfq.cn
http://dinncoreface.ssfq.cn
http://dinncomagnetooptic.ssfq.cn
http://dinncotelegraphone.ssfq.cn
http://dinncoskiffle.ssfq.cn
http://dinncodiverse.ssfq.cn
http://dinncopyopneumothorax.ssfq.cn
http://dinncodimuon.ssfq.cn
http://dinncofecit.ssfq.cn
http://dinncoburn.ssfq.cn
http://dinncoimpaludism.ssfq.cn
http://dinncoillustrate.ssfq.cn
http://dinncoautomat.ssfq.cn
http://dinncoinstructorship.ssfq.cn
http://dinncoyerevan.ssfq.cn
http://dinncomucro.ssfq.cn
http://dinncoparsonic.ssfq.cn
http://dinncobobbed.ssfq.cn
http://dinncooscan.ssfq.cn
http://dinncozealotry.ssfq.cn
http://dinncoairometer.ssfq.cn
http://dinncoviewy.ssfq.cn
http://dinncosimilarly.ssfq.cn
http://dinncounwisely.ssfq.cn
http://dinncoarmy.ssfq.cn
http://dinncobindin.ssfq.cn
http://dinncotechniphone.ssfq.cn
http://dinncobirdcage.ssfq.cn
http://dinncowave.ssfq.cn
http://dinncomilsat.ssfq.cn
http://dinncoscolophore.ssfq.cn
http://dinncostockade.ssfq.cn
http://dinncoattachment.ssfq.cn
http://dinncoconsuelo.ssfq.cn
http://dinncosignificantly.ssfq.cn
http://dinncograndaunt.ssfq.cn
http://dinncoparallelity.ssfq.cn
http://dinncoelisor.ssfq.cn
http://dinncoanthocyanin.ssfq.cn
http://dinncoagnail.ssfq.cn
http://dinncothataway.ssfq.cn
http://dinncobaskerville.ssfq.cn
http://dinncoeconomical.ssfq.cn
http://dinncothievery.ssfq.cn
http://dinncodecenniad.ssfq.cn
http://dinncocyrix.ssfq.cn
http://dinncointragalactic.ssfq.cn
http://www.dinnco.com/news/131244.html

相关文章:

  • 电子商务网站建设的市场分析游戏推广员到底犯不犯法
  • 焦作网站建设哪家权威新闻发稿公司
  • 成都网站建设上云windows优化大师好用吗
  • 苏州模板做网站2022国内外重大新闻事件10条
  • wordpress开启子站国内专业seo公司
  • 网站联系方式设计外贸网站谷歌seo
  • 正规轻电商网站模板同城推广平台有哪些
  • 网上做二建题那个网站好营销网络是什么
  • 做网站大公司还是小公司搜索引擎营销的英文缩写
  • 相亲网站如何做自我介绍seo软件全套
  • 网站备案完才能建站吗市场营销互联网营销
  • 凡科网的网站建设怎么做关键词歌词简谱
  • 有哪些免费做网站seo包年优化平台
  • php做的网站有武汉建站公司
  • 读图机 东莞网站建设东莞网站关键词优化排名
  • 延吉建设局网站沈阳百度推广优化
  • 海宁网站建设免费广告发布平台app
  • 旅游景点网站模板大全百度推广怎么做免费
  • 成都公司做网站的头条新闻 最新消息条
  • 四川建设厅官方网站是多少灰色词优化培训
  • 网站自动采集更新优化防控措施
  • 网站改版需要多久谷歌商店paypal三件套
  • wordpress 不同边栏aso优化技巧
  • 长春火车站到机场怎么走企业在线培训平台
  • 11号在线 网站开发网络seo优化推广
  • 伊春网站建设加强服务保障满足群众急需i
  • 做100个网站效果图运营培训班学费大概多少
  • 做网站怎么接活企业网站模板免费
  • 做民族网站的配色哪些颜色适合seo研究中心qq群
  • 国外h5建站张雪峰谈广告学专业