介绍
组合 API 是一个 API,您可以在其中以易于组合的方式在 setup
选项中编写数据和逻辑。
如果您使用的是 Typescript,强烈建议您开始使用组合 API,因为它的类型功能是任何其他 Vue API 都无法比拟的。
了解更多关于组合 API 的信息 这里.
以下是一个使用此 API 的示例
vue
<script>
export default {
props: ['userId'],
setup (props) {
// Add data and logic here...
// Expose things to the template
return {
props.userId,
}
},
}
</script>