vue3 CompositionAPI 函数以及变量抽离成单独的文件
新建hooks.ts
import { ref, onMounted } from 'vue'
export default function useRooks() { const list = ref([]) const showShare = ref (false) const onShow = () => { showShare.value = true }
const onHandle = () => { getdata() }
let time = 1 let data = [{}] const getdata = () => { time = time + 1 console.log(time) new Promise((resolve, reject) => { data = [...data, {}] list.value = data resolve(true) }) }
onMounted(() => { getdata() })
return { getdata, list, onShow, showShare, onHandle, } }