Skip to content

Commit

Permalink
feat: add callback option
Browse files Browse the repository at this point in the history
  • Loading branch information
yue1123 committed Nov 16, 2022
1 parent b0d8e3a commit 79dd423
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions packages/hooks/useBrowserLocation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ref } from 'vue'
import { ref, Ref } from 'vue'
import { Point } from './usePoint'

interface UseLocationOptions {
/**
Expand Down Expand Up @@ -36,9 +37,23 @@ const statusMap: Record<number, Status> = {
6: 'ERR_PERMISSION_DENIED'
}

export function useBrowserLocation(options?: UseLocationOptions) {
interface Location {
accuracy: number
point: Point
address: {
country: string
city: string
city_code: string
district: string
province: string
street: string
street_number: string
}
}

export function useBrowserLocation(options?: UseLocationOptions, cal?: (location: Ref<Location>) => void) {
options = options || {}
const location = ref({})
const location = ref<Location>({} as Location)
const isLoading = ref<boolean>(true)
const isError = ref<boolean>(false)
const status = ref<Status>()
Expand All @@ -64,6 +79,7 @@ export function useBrowserLocation(options?: UseLocationOptions) {
})
.then((res) => {
location.value = res
cal && cal(location)
})
.catch(() => {
isError.value = true
Expand Down

0 comments on commit 79dd423

Please sign in to comment.