JSX在VUE上传播属性



我正在尝试在vue组件上使用jsx spread属性。

<script>
const
Square = p => <button class="square" v-on:click={ () => p.props.click( p.props.index ) }>{ p.props.squares[ p.props.index ] }</button>
const
Board = p => (
    <div>
        <Square squares={ p.props.squares } click={ p.props.click } index='0' />
        <Square { ...p.props } index='1' />
    </div>
)
export default {
    data    : () => ( { squares: [ 0, 1, 2, 3, 4, 5, 6, 7, 8 ] } )
,   render  ( h )   { return <Board squares={ this.squares } click={ this.handleClick } /> }
,   methods : {
        handleClick: i => console.log( i )
    }
}
</script>

这一行还可以:

<Square squares={ p.props.squares } click={ p.props.click } index='0' />

但是这条线似乎无法将属性从"板"传递给"正方形"

<Square { ...p.props } index='1' />

请帮助我。预先感谢。

也许您可以这样做

<Square { ...{props: p.props} } index='1' />

阅读https://github.com/vuejs/jsx#attributesprops,我认为它可以起作用。

最新更新