forked from vuejs/docs
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathget-position-button.vue
68 lines (63 loc) · 1.3 KB
/
get-position-button.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<template>
<button
v-if="geolocationSupported"
@click="requestPosition"
:disabled="requesting"
class="get-position-button"
>
<i v-if="requesting" class="fa fa-refresh rotating-clockwise"></i>
<template v-else>
<i class="fa fa-map-marker"></i>
<span>
<slot>Find near me</slot>
</span>
</template>
</button>
</template>
<script>
export default {
data: () => ({
geolocationSupported: false,
requesting: false
}),
mounted () {
if ('geolocation' in window.navigator) {
this.geolocationSupported = true
}
},
methods: {
requestPosition () {
this.requesting = true
window.navigator.geolocation.getCurrentPosition(
position => {
this.requesting = false
this.$emit('positionRetrieved', position)
},
error => {
this.requesting = false
this.$emit('positionErrored')
},
{
enableHighAccuracy: true
}
)
}
}
}
</script>
<style lang="scss" scoped>
button {
display: inline-block;
padding: 0.4em 0.7em 0.45em;
font-weight: bold;
font-size: 0.5em;
text-transform: uppercase;
line-height: 1;
border: none;
background: #304455;
color: #fff;
border-radius: 3px;
position: relative;
cursor: pointer;
}
</style>