朱丽叶

导航

vue3+Ts prop的基本使用

<script lang="ts" setup>
  // 定义需要传入的props类型
  interface PropsType {
    optins?: opertionBtns[]
    name: string
  }

  // 导入withDefaults父默认值
  import { withDefaults } from 'vue'

  // 定义props
  const props = withDefaults(defineProps<PropsType>(), {
    name: 'test',
    optins: () => []
  })


  // 使用props
  console.log(props.name)
</script>

posted on 2022-06-23 00:22  朱丽叶  阅读(1802)  评论(0)    收藏  举报