vue3非 setup 语法糖如何在 css v-bind 中使用当前组件的 props?-灵析社区

明道

props 只会在 template 里自动展开,但 style 里并不会。style 里只能访问到你 setup 里 return 的那些成员。所以你要想访问 props,把它 return 就好了: export default { /* 略 */ setup(props) { return { props }; } } .download-btn { width: v-bind('props.width'); height: v-bind('props.height'); color: v-bind('props.color'); background-color: v-bind('props.bgColor'); /* 略 */ }

阅读量:1

点赞量:0

问AI