vue3的<setup script>中使用異步函數

由於vue3的setup一般情況下不允許為async,如果要將setup變成async,則要引入異步組件

	<Suspense>
		<template #default>
			<SwitchMaintenanceUpdate/>
		</template>
	</Suspense>

引入組件的代碼這樣寫

let SwitchMaintenanceUpdate = defineAsyncComponent(()=>import("@/components/pc/SwitchMaintenanceUpdate"))

這樣,子組件的setup函數就可以加上async了

儅子組件使用<script setup>時如果標簽内含有async函數時也一樣處理(PS:生命周期内的async不算)

對vue3的新特性掌握還是不夠啊

posted @ 2022-11-17 09:45  BigFace123  阅读(334)  评论(0)    收藏  举报