命名规则:use--->谁相关.js/ts
举例:
import {reactive} from 'vue'
import axios from 'axios'export default function(){let dogList = reactive({'https://images.dog.ceo/breeds/pembroke/n02113023_4373.jpg'
})//方法
async function getDog(){try{let result = await axios.get("https://dog.ceo/api/bread/pembroke/images")dogList.push(result.data.message)}catch(error){alert(error)
}//向外部暴露内容return {dogList,getDog}
}}
页面中如何使用:
import useDog from '@/hooks/useDog'
const { dogList,getDog() } = ustDog()