|
slot-scope,跟官网一样,我个人觉得slot-scope就是作用域插槽。并且他是接收子组件传来的数据。
举个栗子:
父组件: <template>
<div class="father">
<h3>这里是父组件</h3>
<slot-scope-child>
<template slot-scope="user">
<ul>
<li v-for="(item, index) in user.data" :key="index">pw_item</li>
</ul>
</template>
</slot-scope-child>
</div>
</template>
<script>
import SlotScopeChild from '@/common/SloteScopeChild'
export default {
components: {
SlotScopeChild
}
}
</script>
<style scoped>
</style>子组件:<template>
<div class="child">
<h3>这里是子组件</h3>
<slot :data="data"></slot>
</div>
</template>
<script>
export default {
data: function(){
return {
data: ['空空如也','悟空','成都','七月上','病变','走马']
}
}
}
</script>然后你就会发现,子组件里面的数据会展示出来。这也就是slot-scope。就是带着数据跑。数据在子组件,然后绑到父组件,父组件就可以使用了。这个在elementUI中展示的很好。参考:https://www.cnblogs.com/-wch/p/9766741.html |
|
|