gpt4 book ai didi

javascript - JSX 在 Vue 上传播属性

转载 作者:行者123 更新时间:2023-12-03 00:00:32 27 4
gpt4 key购买 nike

我正在尝试在 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' />

但是这条线似乎无法将属性从“Board”传递到“Square”

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

请帮助我。提前致谢。

最佳答案

也许你可以这样做

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

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

关于javascript - JSX 在 Vue 上传播属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55194194/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com