Add (nav): share button

This commit is contained in:
2023-11-23 15:25:50 +08:00
parent 102517168b
commit 03427352d1
15 changed files with 42 additions and 22 deletions

View File

@@ -1,12 +1,21 @@
<template>
<div>
<button
v-if="isMobileDevice"
type="button"
class="align-self-center btn btn-outline-light ms-2"
class="align-self-center btn btn-link text-white ms-2"
@click="handleShareButton"
>
<i class="bi bi-share-fill"></i>
</button>
<button
v-else
type="button"
class="align-self-center btn btn-light ms-2"
@click="handleShareButton"
>
<i class="bi bi-share-fill"></i> Share
</button>
<!-- Modal -->
<div
@@ -63,6 +72,18 @@ export default {
shareUrl: null,
};
},
computed: {
isMobileDevice() {
if (
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
navigator.userAgent,
)
) {
return true;
}
return false;
},
},
methods: {
handleShareButton() {
if (navigator.share) {
@@ -89,12 +110,13 @@ export default {
})
.then(() => console.log("Successful share"))
.catch((error) => {
this.showModal = true;
// this.showModal = true;
});
} else {
this.showModal = true;
}
},
copyLink() {
navigator.clipboard
.writeText(this.shareUrl)