Problems with scope slots of vue

complete code:

< html lang= "en" >
< head >

<meta charset="UTF-8">
<title>Vue</title>
<link rel="stylesheet" href="./main.css">
<script src="./vue.js"></script>

< / head >
< body >

<h1>Vue</h1>
<hr>

<strong></strong>

<div id="app"> <child> <div slot-scope="news"> <li v-for="item in news.news" >{{item}}</li> <li>{{news}}</li> <li>{{news.news}}</li> </div> </child> </div> <script> Vue.component("child",{ data(){ return{ news:[ "iphone" ,"" ,"F4 " ,"" ,"" ,"" ,"" ,"" ,"" ], } }, template:` <div> : <slot :news="news"></slot> </div> ` }) var vm = new Vue({ el:"-sharpapp", }) </script>

< / body >
< / html >
question: the scope slot binds the news array through attributes, but why is an object received through slot-scope="news"? Please explain, thank you

clipboard.png

Apr.11,2021

because slot-scope only exposes a scope object, it doesn't transfer
under your name. Maybe it's because there's only one attribute that makes you look a little bit around. The following example may make it easier for you to understand

.
<slot :news='news' :index="index"></slot>
<template slot-scope="scope">
  {{ scope.news }}
  {{ scope.index }}
</template>

if you want to make the code more intuitive, you can structure slot-scope

directly.
<template slot-scope="{ news }">
  {{ news }}
</template>

official website is used after structure
ide/components-slots.html-sharp%E8%A7%A3%E6%9E%84-slot-scope" rel=" nofollow noreferrer "> slot

Menu