1 Star 0 Fork 0

WZC/vue2.x-学习笔记

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
插槽2.html 1.59 KB
一键复制 编辑 原始数据 按行查看 历史
WZC 提交于 2020-12-11 21:46 +08:00 . 2020-12-11
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>插槽2</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<style>
</style>
</head>
<!--
作用域插槽
1.为了让 item 在父级的插槽内容中可用,我们可以将 item 作为 <slot> 元素的一个特性绑定上去:称为插槽 prop
<slot :item="item">{{ item.text }}</slot>
2.现在在父级作用域中,我们可以给 v-slot 带一个值来定义我们提供的插槽 prop 的名字:
<template v-slot="slotProps">{{ slotProps.item.text }}</template>
例子:让数据中指定一条数据为红色 (第三条)
-->
<body>
<div id="vue1">
<child :list="list">
<template v-slot="slotProps">
<strong style="color:#f00" v-if="slotProps.item.id == 2">{{ slotProps.item.text }}</strong>
<span v-else>{{ slotProps.item.text }}</span>
</template>
</child>
</div>
<script>
Vue.component('child', {
props: ['list'],
template: `
<ul>
<li v-for="item in list" :key="item.id">
<slot :item="item">{{ item.text }}</slot>
</li>
</ul>
`
})
var vue1 = new Vue({
el: '#vue1',
data: {
list: [
{ id: 0, text: 'one' },
{ id: 1, text: 'two' },
{ id: 2, text: 'three' }
]
}
})
</script>
</body>
</html>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ST_wzc/vue-learning-notes.git
git@gitee.com:ST_wzc/vue-learning-notes.git
ST_wzc
vue-learning-notes
vue2.x-学习笔记
master

搜索帮助