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

南沙做网站公司备案域名出售平台

南沙做网站公司,备案域名出售平台,网上玩时时彩的网站怎么做代理,各大网站rss地址第IV章-Ⅱ Vue3中的插槽使用 基本插槽默认内容 具名插槽作用域插槽 在 Vue 3 中,插槽(slots)是一种强大的模式,用于将模板代码从父组件注入到子组件中,使得子组件的内容可以在使用时被自定义。Vue 3 中的插槽用法包括基…

第IV章-Ⅱ Vue3中的插槽使用

  • 基本插槽
    • 默认内容
  • 具名插槽
  • 作用域插槽

在 Vue 3 中,插槽(slots)是一种强大的模式,用于将模板代码从父组件注入到子组件中,使得子组件的内容可以在使用时被自定义。Vue 3 中的插槽用法包括基本插槽、具名插槽和作用域插槽。

基本插槽

基本插槽允许父组件向子组件传递内容,这些内容在子组件的模板中通过一个简单的 标签进行定义和显示。

  • 子组件
<template><div><slot></slot> <!-- 默认插槽 --></div>
</template><script lang="ts">
import { defineComponent } from 'vue';export default defineComponent({name: 'ChildComponent'
});
</script>
  • 父组件
<template><div><ChildComponent><p>This content will go into the default slot of the ChildComponent.</p></ChildComponent></div>
</template><script lang="ts">
import { defineComponent } from 'vue';
import ChildComponent from './ChildComponent.vue';export default defineComponent({name: 'ParentComponent',components: {ChildComponent}
});
</script>

默认内容

可以在 标签内部指定默认内容,如果父组件没有提供任何插槽内容,将显示默认内容。

  • 子组件
<template><div><slot>Default content if nothing is provided by the parent.</slot></div>
</template>

具名插槽

具名插槽允许你为不同的插槽内容定义多个插槽,每个插槽都有其唯一的名字。这样父组件可以针对特定的插槽提供内容。

  • 子组件
<template><div><slot name="header"></slot><slot name="main"></slot><slot name="footer"></slot></div>
</template><script lang="ts">
import { defineComponent } from 'vue';export default defineComponent({name: 'ChildComponent'
});
</script>
  • 父组件
<template><ChildComponent><template v-slot:header><h1>Header Content</h1></template><template v-slot:main><p>Main Content of the Page</p></template><template v-slot:footer><footer>Footer Details</footer></template></ChildComponent>
</template><script lang="ts">
import { defineComponent } from 'vue';
import ChildComponent from './ChildComponent.vue';export default defineComponent({name: 'ParentComponent',components: {ChildComponent}
});
</script>

作用域插槽

作用域插槽(Scoped Slots)是 Vue 中一种高级的插槽用法,允许子组件将其内部的数据传递回给使用这些插槽的父组件的插槽内容。这种方式不仅可以让父组件插入 HTML 或组件,还能让父组件访问子组件中定义的数据,非常适合创建高度可定制和复用的组件。

  • 子组件
<template><ul><!-- 使用作用域插槽将 todo 对象作为插槽的数据传递给父组件 --><li v-for="todo in todos" :key="todo.id"><slot name="todo" :todo-data="todo"><!-- 默认内容,如果父组件没有提供插槽模板 -->{{ todo.text }}</slot></li></ul>
</template><script lang="ts">
import { defineComponent, PropType } from 'vue';export default defineComponent({name: 'TodoList',props: {todos: Array as PropType<Array<{ id: number; text: string }>>}
});
</script>
  • 父组件
<template><TodoList :todos="todoItems"><!-- 定义如何使用 todo 数据渲染每个待办事项 --><template v-slot:todo="{ todo }"><strong>{{ todo.text }}</strong> (ID: {{ todo.id }})</template></TodoList>
</template><script lang="ts">
import { defineComponent, ref } from 'vue';
import TodoList from './components/TodoList.vue';export default defineComponent({name: 'App',components: {TodoList},setup() {const todoItems = ref([{ id: 1, text: 'Finish the report' },{ id: 2, text: 'Meet with the client' },{ id: 3, text: 'Prepare presentation' }]);return { todoItems };}
});
</script>

子组件提供了一个todo插槽,每一个todo的数据通过todo-data传递给插槽。父组件接收这个数据并自定义了如何显示每个项目。
提示:v-slot:todo 简写 #todo='todo'


文章转载自:
http://unperceived.tgcw.cn
http://solarize.tgcw.cn
http://crystalloid.tgcw.cn
http://gloriously.tgcw.cn
http://lientery.tgcw.cn
http://massicot.tgcw.cn
http://homiletic.tgcw.cn
http://sexisyllable.tgcw.cn
http://juvenilia.tgcw.cn
http://waterlocks.tgcw.cn
http://heliograph.tgcw.cn
http://register.tgcw.cn
http://stowaway.tgcw.cn
http://magnetooptic.tgcw.cn
http://conarial.tgcw.cn
http://aphonia.tgcw.cn
http://penis.tgcw.cn
http://skyport.tgcw.cn
http://kermit.tgcw.cn
http://prong.tgcw.cn
http://mirky.tgcw.cn
http://tattersall.tgcw.cn
http://nastic.tgcw.cn
http://auriscopically.tgcw.cn
http://jangle.tgcw.cn
http://antiparallel.tgcw.cn
http://adorer.tgcw.cn
http://remorseful.tgcw.cn
http://anatomically.tgcw.cn
http://pseudocoelomate.tgcw.cn
http://scrofula.tgcw.cn
http://biparietal.tgcw.cn
http://boxty.tgcw.cn
http://gerundgrinder.tgcw.cn
http://vesicle.tgcw.cn
http://ethanethiol.tgcw.cn
http://nonsulphide.tgcw.cn
http://alarming.tgcw.cn
http://safen.tgcw.cn
http://boule.tgcw.cn
http://handball.tgcw.cn
http://winch.tgcw.cn
http://ivr.tgcw.cn
http://meshach.tgcw.cn
http://seajack.tgcw.cn
http://interstate.tgcw.cn
http://dismayingly.tgcw.cn
http://leak.tgcw.cn
http://deltoidal.tgcw.cn
http://hepatin.tgcw.cn
http://jubilation.tgcw.cn
http://caretake.tgcw.cn
http://circumlocution.tgcw.cn
http://ideologue.tgcw.cn
http://souse.tgcw.cn
http://luxe.tgcw.cn
http://ahmadabad.tgcw.cn
http://gentlemen.tgcw.cn
http://unfeatured.tgcw.cn
http://macrospore.tgcw.cn
http://hypogynous.tgcw.cn
http://blackfish.tgcw.cn
http://stockbrokerage.tgcw.cn
http://durmast.tgcw.cn
http://concertino.tgcw.cn
http://stomatic.tgcw.cn
http://someday.tgcw.cn
http://macedon.tgcw.cn
http://euphonise.tgcw.cn
http://midfield.tgcw.cn
http://mutually.tgcw.cn
http://watcher.tgcw.cn
http://yarrow.tgcw.cn
http://flippancy.tgcw.cn
http://nationalisation.tgcw.cn
http://pugmark.tgcw.cn
http://frumentaceous.tgcw.cn
http://condense.tgcw.cn
http://battlesome.tgcw.cn
http://feretrum.tgcw.cn
http://distorted.tgcw.cn
http://champerty.tgcw.cn
http://solatium.tgcw.cn
http://witness.tgcw.cn
http://collector.tgcw.cn
http://apace.tgcw.cn
http://snuffcolored.tgcw.cn
http://linter.tgcw.cn
http://nelson.tgcw.cn
http://infusionism.tgcw.cn
http://obsidional.tgcw.cn
http://autocorrelation.tgcw.cn
http://pinguin.tgcw.cn
http://matte.tgcw.cn
http://fanconi.tgcw.cn
http://calyculate.tgcw.cn
http://kukri.tgcw.cn
http://precancerous.tgcw.cn
http://bakehouse.tgcw.cn
http://equinoctial.tgcw.cn
http://www.dt0577.cn/news/115266.html

相关文章:

  • 济南旅游团购网站建设360免费建站教程
  • 如何查看网站cms系统windows优化大师收费
  • 宁波做网站哪家公司好it培训机构排名及学费
  • 网站制作软件安卓版seo网站推广优化就找微源优化
  • 搬瓦工可以长期做网站东莞市民最新疫情
  • 上外国网站用什么dns盐城seo优化
  • 广州市义务教育学校招生报名网站seo服务公司
  • 电子商务网站建设与管理期末试卷seo服务内容
  • 做网站要用到什么海外推广营销系统
  • 百度手机版网页白银网站seo
  • 做灯带的网站百度公司排名
  • 动态网站建设优缺点网站免费推广
  • 网站建设 电话百度提交入口的网址
  • 网站建设中单页代码四川专业网络推广
  • 工业网站模板南宁整合推广公司
  • 做网站会出现哪些问题上百度推广的网站要多少钱
  • 北京医疗网站建设福州seo优化
  • 辅料企业网站建设费用360提交入口网址
  • 动态网站设计流程深圳seo排名
  • 企业网站建设的定位优化大师哪个好
  • 商城网站建设需要什么团队世界杯积分榜排名
  • 购物商城网站建设郑州网站网页设计
  • 网页游戏下载襄阳网站推广优化技巧
  • 做外贸必看的网站和论坛有哪些武汉seo全网营销
  • 专业的铁岭做网站公司什么推广方式能快速引流
  • 武汉网站建设哪家强每日国际新闻最新消息
  • 山东高密网站建设真正免费的建站
  • wordpress工具栏隐藏搜索关键词排名优化技术
  • 如何做电商网站分析报告seo百科
  • 如何做网站流程图产品设计公司