Sfoglia il codice sorgente

1,提的问题修改 功能开发 1,钱包断开连接(使用disconnect方法尝试断开连接,发现disconnect方法 不起作用,查看官方文档后发现已经弃用,选择accountsChanged方法解决) 2,钱包连接,获取钱包地址及整体逻辑开发

jhaoG 3 settimane fa
parent
commit
cb7d721dcb

+ 19 - 11
src/App.vue

@@ -1,19 +1,27 @@
 <template>
-  <router-view/>
+  <router-view />
 </template>
 
 <script setup>
-/*import { useI18n } from 'vue-i18n';
-const { locale } = useI18n();*/
-// 必要时加上去
+  import { l_removeItem } from "@/utils/storage";
+  // 必要时加上去
+  // import { useI18n } from 'vue-i18n';
+  // const { locale } = useI18n();
+
+  // 监控钱包是否断开连接
+  ethereum.on("accountsChanged", (accounts) => {
+    if (accounts.length === 0) {
+      l_removeItem("address");
+    }
+  });
 </script>
 
 <style>
-* {
-  -webkit-overflow-scrolling: touch;
-}
+  * {
+    -webkit-overflow-scrolling: touch;
+  }
 
-* {
-  -webkit-tap-highlight-color: transparent;
-}
-</style>
+  * {
+    -webkit-tap-highlight-color: transparent;
+  }
+</style>

BIN
src/assets/img/index/Bank_transfer_2_.png


+ 11 - 1
src/views/index/ApplyPermission.vue

@@ -15,9 +15,19 @@
   </div>
 </template>
 <script setup>
+  import { l_setItem, l_removeItem } from "@/utils/storage";
+  import { useRouter } from "vue-router";
+
+  const router = useRouter();
+
   const sure = async () => {
     const accounts = await ethereum.request({ method: "eth_requestAccounts" });
-    console.log(1, accounts);
+    const address = accounts[0];
+
+    if (address) {
+      l_setItem("address", address);
+      router.push("/");
+    }
   };
 </script>
 <style lang="less" scoped>