hooks使用,听起来就很高大上,但我感觉就是装杯版的封装方法
hooks文件里
import { onMounted } from 'vue'
// 赋码
export const useIDCard = () =>{
let aa = 11;
//只有放在这里才能调用周期函数
onMounted(() =>{
console.log('fffffffffffffffffffff')
aa += 55;
})
const getId = () =>{
console.log('ok,你很厉害,执行了我')
return '给你一耳刮子'+aa
}
return {
getId
}
}
页面使用
import { useIDCard } from '@/hooks/xxxxxxx' //引入hooks
const { getId } = useIDCard();
let result = getId();
console.log('揭晓答案',result )