|
@@ -1,37 +1,34 @@
|
|
-import wxshare from '@/utils/wxshare'
|
|
|
|
-import { onMounted } from 'vue';
|
|
|
|
-
|
|
|
|
-const initWxShare = async => {
|
|
|
|
- onMounted(async () => {
|
|
|
|
- try {
|
|
|
|
- await new Promise(r => setTimeout(r, 1000));
|
|
|
|
- const title = document.title;
|
|
|
|
- const link = window.location.href
|
|
|
|
- // const desc = '测试微信分享'
|
|
|
|
- const imgUrl = document.querySelector('meta[name="cover"]').content || '';
|
|
|
|
- const desc = document.querySelector('meta[name="description"]').content || '';
|
|
|
|
- // const imgUrl = document.document.querySelector('meta[name="description"]').content
|
|
|
|
- // title, link, imgUrl, desc
|
|
|
|
- console.log('当前分享imgUrl', imgUrl)
|
|
|
|
- await wxshare({
|
|
|
|
- title,
|
|
|
|
- link,
|
|
|
|
- desc,
|
|
|
|
- imgUrl
|
|
|
|
- });
|
|
|
|
- } catch (error) {
|
|
|
|
- console.error(error)
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- })
|
|
|
|
-}
|
|
|
|
|
|
+import wxshare from "@/utils/wxshare";
|
|
|
|
+import { onMounted } from "vue";
|
|
|
|
|
|
|
|
+const initWxShare = async () => {
|
|
|
|
+ // onMounted(async () => {
|
|
|
|
+ try {
|
|
|
|
+ await new Promise((r) => setTimeout(r, 1000));
|
|
|
|
+ const title = document.title;
|
|
|
|
+ const link = window.location.href;
|
|
|
|
+ // const desc = '测试微信分享'
|
|
|
|
+ const imgUrl = document.querySelector('meta[name="cover"]').content || "";
|
|
|
|
+ const desc =
|
|
|
|
+ document.querySelector('meta[name="description"]').content || "";
|
|
|
|
+ // const imgUrl = document.document.querySelector('meta[name="description"]').content
|
|
|
|
+ // title, link, imgUrl, desc
|
|
|
|
+ console.log("当前分享imgUrl", imgUrl);
|
|
|
|
+ await wxshare({
|
|
|
|
+ title,
|
|
|
|
+ link,
|
|
|
|
+ desc,
|
|
|
|
+ imgUrl,
|
|
|
|
+ });
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.error(error);
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ // })
|
|
|
|
+};
|
|
|
|
|
|
export function useWxShared() {
|
|
export function useWxShared() {
|
|
- return {
|
|
|
|
- initWxShare,
|
|
|
|
- };
|
|
|
|
-}
|
|
|
|
|
|
+ return {
|
|
|
|
+ initWxShare,
|
|
|
|
+ };
|
|
|
|
+}
|