代码如下:
<div id="root">
<child>
<template slot-scope="props">
<li>{{props.item}}</li>
</template>
</child>
</div>
<script>
Vue.component('child',{
data:function(){
return{
list:[1,2,3,4,5]
}
},
template:`<div>
<ul>
<slot v-for="item of list"
:item=item
></slot>
</ul>
</div>`
});
var vm=new Vue({
el: '#root',
});
</script>
按照您的视频尝试了两次,依然未看出跟您的代码有何区别,直接在子组件内进行li循环可以显示list,使用solt就一直是同样的错误,提示:
Property or method "props" is not defined on the instance but referenced during render. Make sure to declare reactive data properties in the data option.
TypeError: Cannot read property 'item' of undefined
麻烦您帮忙看一下好吗?谢谢了
课程紧跟Vue3版本迭代,企业主流版本Vue2+Vue3全掌握
了解课程