admin管理员组文章数量:1405898
I'm trying to use JSX Spread Attributes on Vue ponent like below.
<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>
This line is OK:
<Square squares={ p.props.squares } click={ p.props.click } index='0' />
But this line seems to fail to pass properties from 'Board' to 'Square'
<Square { ...p.props } index='1' />
Please help me. Thanks in advance.
I'm trying to use JSX Spread Attributes on Vue ponent like below.
<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>
This line is OK:
<Square squares={ p.props.squares } click={ p.props.click } index='0' />
But this line seems to fail to pass properties from 'Board' to 'Square'
<Square { ...p.props } index='1' />
Please help me. Thanks in advance.
Share Improve this question edited Mar 22, 2019 at 15:52 Patrick Roberts 52.1k10 gold badges117 silver badges163 bronze badges asked Mar 16, 2019 at 6:47 SatachitoSatachito 5,88838 silver badges43 bronze badges 2-
1
Coming from react, I never understand the value of spreading the props. Even using flow/typescript you still had to dig to find out what's actually being passed and where a collision is. But to answer your question, vue uses babel sugar syntax in order to bind properties. You can't spread them on SFCs, but you can using
render ponents
. – Ohgodwhy Commented Mar 16, 2019 at 7:23 - Thanks for your suggestion. I moved my code into js part of the project but still not able to find any glue. I will struggle more. Thanks! – Satachito Commented Mar 16, 2019 at 9:11
1 Answer
Reset to default 7Maybe you can do like this
<Square { ...{props: p.props} } index='1' />
After reading https://github./vuejs/jsx#attributesprops, I think it could works.
本文标签: javascriptJSX Spread Attributes on VueStack Overflow
版权声明:本文标题:javascript - JSX Spread Attributes on Vue - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744938630a2633343.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论