-
Notifications
You must be signed in to change notification settings - Fork 3
/
NavigatorShare.vue
53 lines (50 loc) · 1023 Bytes
/
NavigatorShare.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
<template>
<div @click="share()">
<slot v-if="hasSlot()" name="clickable">
</slot>
<p v-else>Share</p>
</div>
</template>
<script>
export default {
props: {
title: String,
text: String,
url: {
type: String,
required: true
},
onError: Function,
onSuccess: Function,
},
methods: {
hasSlot() {
return !!this.$slots['clickable']
},
share() {
const data = {
title: this.title,
text: this.text,
url: this.url
};
if (navigator.share) {
navigator.share(data)
.then((succ) => {
if (succ) {
this.onSuccess(succ);
}
})
.catch((err) => {
if (onError) {
this.onError(err);
}
})
} else {
if (this.onError) {
this.onError('method not supported');
}
}
}
}
}
</script>