0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[Vue.js] スコープ付きslotの記述方法

Last updated at Posted at 2022-08-31

子コンポーネント側

子コンポーネント側では、<slot>タグに対してv-bindを行います。

<template>
  <div>
    <slot :hoge="hoge">
  </div>
</template>

<script>
export default {
  name: 'Child',
  data () {
    return {
      hoge: 'hoge',
    }
  }
}
</script>

親コンポーネント側

親コンポーネント側では<v-slot:default>で受け取ることで、子コンポーネントのの値をとることができます。
slotPropsは任意ですので重複がなければ、どんな文字列でも構いません。

<template>
  <div>
    <Child v-slot:default="slotProps">
      {{ slotProps.hoge }}
    </Child>
  </div>
</template>

<script>
import MyCom from '../components/Child.vue'
export default {
  name: 'parent',
  components: {
    Child
  }
}
</script>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?