Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
471 views
in Technique[技术] by (71.8m points)

vue.js - How to get vue slot property in JSX?

I write a child component used template syntax, child component has a slot that transmits 'item' property to parent component, but parent component use JSX syntax, now I have trouble how to get 'item' property in JSX. Any help would be greatly appreciated!

// child.vue
<template>
  <Autocomplete>
    <template slot-scope="{ item }">
      <slot :item="item" />
    </template>
  </Autocomplete>
</template>
// parent.vue
export default {
  render () {
    return (
      <Child>
        <template slot-scope='{item}'>
          <span>{item}</span> // item is not defined 
        </template>
      </Child>
    )
  }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Can you try this?

// child.vue
<template>
  <Autocomplete>
    <template v-slot="{ item }">
      <slot :item="item" />
    </template>
  </Autocomplete>
</template>

And in the parent component:

// JSX
{
  render () {
    return (
      <Child>
        <template v-slot="{ item }">
          <span>{{item}}</span> // item is not defined 
        </template>
      </Child>
    )
  }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...