代码拉取完成,页面将自动刷新
<!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>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。