首页 > 技术文章 > vue3.0 语法糖 script 标签里面添加 setup

shiazhen 2021-07-09 10:10 原文

vue3.0 使用setup 语法糖

使用 props

import { defineProps} from 'vue'
const props = defineProps({
  total: {
    type: Number,
    default: 0
  },
  page: {
    type: Number,
    default: 2
  }
})

使用 emit

<script setup>
import { defineEmits } from 'vue'
const emit = defineEmits(['update:page'])
</script>

使用 attr

<script setup>
import { useAttrs} from 'vue'
const attrs = useAttrs()
</script>

使用 Slot

<script setup>
import { useSlots} from 'vue'
const slots = useSlots()
</script>

推荐阅读