Skip to main content

Command Palette

Search for a command to run...

vue2 的v-slot

Updated
1 min readView as Markdown

demo效果

<!-- VSlotWomo.vue -->
<template>
<div>
  <child>
    <!-- 作用域插槽是什么呢?就是子组件提供数据,父组件拿来用,
    父组件可以决定数据如何显示,以什么形式显示 -->
    <template v-slot:dd="{por}">
      <div style="color: blue;">子组件提供的数据是{{ por }}</div>
    </template>
  </child>
</div>
</template>
<script>
import child from "./child.vue";
export default {
  components: {
    child,
  }
}
</script>
<!-- child.vue -->
<template>
<div>
  <slot name="dd" :por="objx"></slot>
</div>
</template>
<script>
export default {
  data() { 
    return {
      objx: 'child-data'
    }
  }
}
</script>

More from this blog

EddieQiao's blog

84 posts

coder, work in suzhou