vue3


新特性

常用的 Composition API

  • getCurrentInstance
  • defineComponent
  • defineAsyncComponent
  • setup
  • ref
  • reactive
  • watchEffect
  • toRef
  • toRefs
  • provide
  • inject
  • readOnly
  • renderList
  • nextTick

script setup Api

  • defineProps
  • defineEmit
  • renderSlots
  • useContext
  • h

example

// setup Component
defineComponent({
  setup(props, { attrs, slots, emit, expose }) {
    ...
    return {}   // 合并data
    // return ()=>{}   render
  },
})
<!-- script setup   -->

<script setup>
  const props = defineProps({
    title: String,
  })
  // props.title
  const { slots, attrs } = useContext()
  // 获取 emit
  const emit = defineEmit(['chang-name'])
  // 调用 emit
  emit('chang-name', 'Tom')
</script>

新的组件

Fragment(片断)

Teleport(瞬移)

Suspense(不确定的)


Author: yanstars
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint policy. If reproduced, please indicate source yanstars !
  TOC