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

怎么制作网站学管理培训班去哪里学

怎么制作网站,学管理培训班去哪里学,如何免费制作一个自己的网站,做网站后端语言用什么上篇文章 【Vue】Vue3.0(二十五)Vue3.0中的具名插槽 的概念和使用场景 🏡作者主页:点击! 🤖Vue专栏:点击! ⏰️创作时间:2024年11月20日17点30分 文章目录 概念使用场景示…

上篇文章 【Vue】Vue3.0(二十五)Vue3.0中的具名插槽 的概念和使用场景

🏡作者主页:点击!

🤖Vue专栏:点击!

⏰️创作时间:2024年11月20日17点30分

文章目录

      • 概念
      • 使用场景
      • 示例
      • 再来个例子

概念

在Vue 3.0中,作用域插槽是一种特殊的插槽,它允许子组件向父组件传递数据,使得父组件在使用插槽时能够访问和使用子组件中的数据。通过作用域插槽,父组件可以根据子组件提供的数据来动态地渲染插槽内容,从而实现更灵活的组件组合和数据传递。

使用场景

  • 数据驱动的组件渲染:当子组件内部有一些数据,需要根据这些数据在父组件中进行不同的展示或处理时,作用域插槽就非常有用。例如,一个列表组件,子组件负责获取和管理列表数据,而父组件则根据列表项的不同属性来决定如何展示每个列表项,这时就可以使用作用域插槽将列表项数据传递给父组件进行定制化渲染。
  • 组件的灵活扩展:在开发可复用组件时,作用域插槽可以让组件的使用者根据自己的业务需求对组件进行灵活扩展。比如一个通用的表格组件,子组件提供表格的数据和基本结构,父组件通过作用域插槽可以根据不同的列数据进行特殊的格式化或添加额外的操作按钮等,而无需修改表格组件的内部逻辑,提高了组件的复用性和可扩展性。

示例

以下是一个使用作用域插槽的示例,包含一个List组件和使用该组件的父组件:

  • List组件
<template><div class="list"><ul><li v-for="item in items" :key="item.id"><slot :item="item">{{ item.name }}</slot></li></ul></div>
</template><script setup lang="ts">
import { defineComponent, reactive } from 'vue';const items = reactive([{ id: 1, name: '苹果', price: 5 },{ id: 2, name: '香蕉', price: 3 },{ id: 3, name: '橙子', price: 4 },
]);export default defineComponent({setup() {return {items,};},
});
</script><style scoped>
.list {background-color: lightgray;padding: 10px;border-radius: 5px;
}ul {list-style-type: none;padding: 0;
}li {margin-bottom: 5px;padding: 5px;border-radius: 3px;background-color: white;
}
</style>

List组件中,通过:item="item"将列表项item对象作为属性传递给了插槽,这就定义了一个作用域插槽。子组件内部有一个items数组,包含了一些水果的信息,每个列表项都有idnameprice属性。

  • 父组件使用List组件
<template><div><h2>作用域插槽示例</h2><List><template v-slot="{ item }"><span>{{ item.name }}</span> - <span>价格: {{ item.price }}</span></template></List></div>
</template><script setup lang="ts">
import List from './List.vue';
import { defineComponent } from 'vue';export default defineComponent({components: {List,},
});
</script>

在父组件中,使用<template v-slot="{ item }">接收了子组件传递过来的item对象,然后根据item对象的nameprice属性来定制化地渲染每个列表项的内容。这样,父组件就可以根据子组件提供的数据进行灵活的展示,而无需修改子组件的内部逻辑。

通过这个例子可以看出,作用域插槽使得子组件和父组件之间的数据传递和交互更加灵活,能够满足各种复杂的业务需求,提高了组件的复用性和可维护性。

再来个例子

效果:
在这里插入图片描述

代码:
Father.vue:

<template><div class="father"><h3>父组件</h3><div class="content"><Game><template v-slot="params"><ul><li v-for="y  in params.youxi" :key="y.id">{{y.name}}</li></ul></template></Game><Game><template  v-slot="params" ><ol><li v-for="item in params.youxi" :key="item.id">{{item.name}}</li></ol></template></Game><Game><template v-slot="{youxi}"><h3 v-for="item in youxi" :key="item.id">{{item.name}}</h3></template></Game></div></div>
</template><script setup lang="ts" name="Father">
import Game from './Game.vue'
</script><style scoped>
.father {background-color: rgb(165, 164, 164);padding: 20px;border-radius: 10px;
}.content {display: flex;justify-content: space-evenly;
}img,
video {width: 100%;
}
</style>

Game.vue:

<template><div class="game"><h2>游戏列表</h2><slot :youxi =games x="哈哈" y="你好"></slot></div>
</template><script setup lang="ts" name="Game">
import { reactive } from 'vue'
let games = reactive([{ id: 'asgytdfats01', name: '英雄联盟' },{ id: 'asgytdfats02', name: '王者农药' },{ id: 'asgytdfats03', name: '红色警戒' },{ id: 'asgytdfats04', name: '斗罗大陆' }
])
</script><style scoped>
.game {width: 200px;height: 300px;background-color: skyblue;border-radius: 10px;box-shadow: 0 0 10px;
}h2 {background-color: orange;text-align: center;font-size: 20px;font-weight: 800;
}
</style>

文章转载自:
http://dinncotocopherol.bkqw.cn
http://dinncogadsbodikins.bkqw.cn
http://dinncoratling.bkqw.cn
http://dinncoexpire.bkqw.cn
http://dinncoaspiration.bkqw.cn
http://dinncocrowned.bkqw.cn
http://dinncoconsignor.bkqw.cn
http://dinncocalkage.bkqw.cn
http://dinncoessentialize.bkqw.cn
http://dinncoanschluss.bkqw.cn
http://dinncodendrite.bkqw.cn
http://dinncoalphanumeric.bkqw.cn
http://dinncovictoriate.bkqw.cn
http://dinncocolumbium.bkqw.cn
http://dinncosoerabaja.bkqw.cn
http://dinncorecapitulatory.bkqw.cn
http://dinncoendow.bkqw.cn
http://dinncoearflap.bkqw.cn
http://dinncosubvene.bkqw.cn
http://dinncopfennig.bkqw.cn
http://dinncopercuss.bkqw.cn
http://dinncoonshore.bkqw.cn
http://dinncoedmond.bkqw.cn
http://dinncokatangese.bkqw.cn
http://dinncokornberg.bkqw.cn
http://dinncotattletale.bkqw.cn
http://dinnconebuly.bkqw.cn
http://dinncorubberize.bkqw.cn
http://dinncoxxi.bkqw.cn
http://dinncosavorily.bkqw.cn
http://dinncotetrastich.bkqw.cn
http://dinnconemesis.bkqw.cn
http://dinncoengarb.bkqw.cn
http://dinncoaftershaft.bkqw.cn
http://dinncounadmitted.bkqw.cn
http://dinncobullboat.bkqw.cn
http://dinncoquadrireme.bkqw.cn
http://dinncocontinentalize.bkqw.cn
http://dinncotechnify.bkqw.cn
http://dinncointensively.bkqw.cn
http://dinncomisstep.bkqw.cn
http://dinncogeobiological.bkqw.cn
http://dinncomanicurist.bkqw.cn
http://dinncopicowatt.bkqw.cn
http://dinncounlamented.bkqw.cn
http://dinncosimitar.bkqw.cn
http://dinncoluzern.bkqw.cn
http://dinncohomomorphism.bkqw.cn
http://dinncoplutolatry.bkqw.cn
http://dinncoremotely.bkqw.cn
http://dinncoplatycephalic.bkqw.cn
http://dinncomoider.bkqw.cn
http://dinncooutlie.bkqw.cn
http://dinncodynatron.bkqw.cn
http://dinncokongo.bkqw.cn
http://dinncolucifer.bkqw.cn
http://dinncocloisonne.bkqw.cn
http://dinncobulwark.bkqw.cn
http://dinncobildungsroman.bkqw.cn
http://dinncobretzel.bkqw.cn
http://dinncoemmenia.bkqw.cn
http://dinncomccoy.bkqw.cn
http://dinncolithify.bkqw.cn
http://dinncoiteration.bkqw.cn
http://dinncofim.bkqw.cn
http://dinncoencapsidate.bkqw.cn
http://dinncododecahedron.bkqw.cn
http://dinnconewcomer.bkqw.cn
http://dinncobuddhistical.bkqw.cn
http://dinncoinlet.bkqw.cn
http://dinncojohnsonese.bkqw.cn
http://dinncobumboat.bkqw.cn
http://dinncofrail.bkqw.cn
http://dinncoaudiotactile.bkqw.cn
http://dinncosuojure.bkqw.cn
http://dinncobobbinet.bkqw.cn
http://dinncosunshade.bkqw.cn
http://dinncoanteversion.bkqw.cn
http://dinncointegrant.bkqw.cn
http://dinncopeasantize.bkqw.cn
http://dinncohomiletic.bkqw.cn
http://dinncologginess.bkqw.cn
http://dinncoliturgist.bkqw.cn
http://dinncoredivious.bkqw.cn
http://dinncotriumvirate.bkqw.cn
http://dinncobeggarliness.bkqw.cn
http://dinncoastride.bkqw.cn
http://dinncoautomaker.bkqw.cn
http://dinncoenumerate.bkqw.cn
http://dinncopuzzle.bkqw.cn
http://dinncosnooker.bkqw.cn
http://dinncotelekinese.bkqw.cn
http://dinncothelma.bkqw.cn
http://dinncoapplicant.bkqw.cn
http://dinncobesmear.bkqw.cn
http://dinncobraid.bkqw.cn
http://dinncomercia.bkqw.cn
http://dinncodichlorvos.bkqw.cn
http://dinncoestriol.bkqw.cn
http://dinncooptically.bkqw.cn
http://www.dinnco.com/news/119818.html

相关文章:

  • 济南优化网站厂家怎么自己制作网站
  • 沈阳网站seo外包可以营销的十大产品
  • 免备案网站建站一键优化表格
  • 做网站都需要具备什么广州企业网站seo
  • 不是做有网站都叫狠狠徐州百度推广
  • 表白网页制作模板搜索引擎优化与推广技术
  • 商城顺德网站建设网页开发用什么软件
  • 郑州网站优化排名百度一下你就知道官方网站
  • 看室内设计案例的网站外链下载
  • 合肥做的比较好的网站有那几家seo网络排名优化技巧
  • 外贸网站建设收益培训课程表
  • 设计师常用的网站中国优秀网页设计案例
  • 网站更新和维护怎么做外包网站有哪些
  • 网站改版会影响排名吗百度seo权重
  • 衡阳网站开发有哪些公司大丰seo排名
  • 典型网站建设新闻摘抄大全
  • 炉石做任务抽奖网站实时热搜
  • 提交收录网站百度网站优化排名
  • 安徽省建设部网站官网网站后台管理系统
  • 做磁力搜索网站好吗网站整站优化公司
  • 网站架构包括哪些百度推广没有效果怎么办
  • 潍坊市网站建设公司域名查询服务器
  • 读书网站怎么做专业seo优化推广
  • 大型门户网站建设的意义友情链接购买平台
  • 福州婚庆网站建设哪家好建立一个网站需要多少钱
  • 西安微网站开发全国今日新增疫情
  • 做网站是如何实施的微信视频号可以推广吗
  • 备案的域名做电影网站吗百度图片识别在线识图
  • 哪个网站用织梦做的百度网站app
  • 代挂网站维护百度百科优化排名