获取您的 自有 Vue 服务器
App.vue
SlotComp.vue
main.js
 
<template>
  <h1>Scoped Slots</h1>
  <p>App.vue controls how the array from the scoped slot is rendered.</p>
  <slot-comp v-slot="food">
    <h2>{{ food.foodName }}</h2>
  </slot-comp>
</template>

<script></script>

<style>
  #app {
    width: 300px;
  }
  h2 {
    background-color: lightgreen;
    padding: 10px;
    margin: 10px;
  }
</style>                  
<template>
    <slot 
    v-for="x in foods" 
    :key="x" 
    :foodName="x"
    ></slot>
</template>

<script>
export default {
    data() {
        return {
            foods: ['Apple','Pizza','Rice','Fish','Cake']
        }
    }
}
</script>

<style></style>                  
import { createApp } from 'vue'

import App from './App.vue'
import SlotComp from './components/SlotComp.vue'

const app = createApp(App)
app.component('slot-comp', SlotComp)
app.mount('#app')
                  
https://127.0.0.1:5173/