{"id":168869,"date":"2024-11-06T16:56:24","date_gmt":"2024-11-06T08:56:24","guid":{"rendered":"https:\/\/server.hk\/cnblog\/168869\/"},"modified":"2024-11-06T16:56:25","modified_gmt":"2024-11-06T08:56:25","slug":"uniapp-%e9%96%8b%e7%99%bc%e4%b8%ad%e7%9a%84%e6%95%b8%e6%93%9a%e5%ba%ab%e6%93%8d%e4%bd%9c%e6%8c%87%e5%8d%97-uniapp-%e6%95%b8%e6%93%9a%e5%ba%ab","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/168869\/","title":{"rendered":"UniApp \u958b\u767c\u4e2d\u7684\u6578\u64da\u5eab\u64cd\u4f5c\u6307\u5357 (uniapp \u6578\u64da\u5eab)"},"content":{"rendered":"<h1 id=\"uniapp-%e9%96%8b%e7%99%bc%e4%b8%ad%e7%9a%84%e6%95%b8%e6%93%9a%e5%ba%ab%e6%93%8d%e4%bd%9c%e6%8c%87%e5%8d%97-uniapp-%e6%95%b8%e6%93%9a%e5%ba%ab-jDTUpXyrhF\">UniApp \u958b\u767c\u4e2d\u7684\u6578\u64da\u5eab\u64cd\u4f5c\u6307\u5357 (uniapp \u6578\u64da\u5eab)<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u79fb\u52d5\u61c9\u7528\u958b\u767c\u4e2d\uff0cUniApp \u4f5c\u70ba\u4e00\u500b\u8de8\u5e73\u53f0\u7684\u958b\u767c\u6846\u67b6\uff0c\u53d7\u5230\u4e86\u5ee3\u6cdb\u7684\u95dc\u6ce8\u3002\u5b83\u5141\u8a31\u958b\u767c\u8005\u4f7f\u7528 Vue.js \u4f86\u69cb\u5efa\u61c9\u7528\uff0c\u4e26\u80fd\u5920\u540c\u6642\u904b\u884c\u65bc\u591a\u500b\u5e73\u53f0\uff0c\u5982 iOS\u3001Android \u53ca\u5404\u7a2e\u5c0f\u7a0b\u5e8f\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e\u5728 UniApp \u958b\u767c\u4e2d\u5982\u4f55\u9032\u884c\u6578\u64da\u5eab\u64cd\u4f5c\uff0c\u5e6b\u52a9\u958b\u767c\u8005\u66f4\u597d\u5730\u7ba1\u7406\u548c\u5b58\u53d6\u6578\u64da\u3002<\/p>\n<h2 id=\"uniapp-%e6%95%b8%e6%93%9a%e5%ba%ab%e6%93%8d%e4%bd%9c%e6%a6%82%e8%bf%b0-jDTUpXyrhF\">UniApp \u6578\u64da\u5eab\u64cd\u4f5c\u6982\u8ff0<\/h2>\n<p>\u5728 UniApp \u4e2d\uff0c\u6578\u64da\u5eab\u64cd\u4f5c\u4e3b\u8981\u4f9d\u8cf4\u65bc\u5169\u7a2e\u65b9\u5f0f\uff1a\u672c\u5730\u6578\u64da\u5eab\u548c\u9060\u7a0b\u6578\u64da\u5eab\u3002\u958b\u767c\u8005\u53ef\u4ee5\u6839\u64da\u61c9\u7528\u7684\u9700\u6c42\u9078\u64c7\u5408\u9069\u7684\u6578\u64da\u5eab\u89e3\u6c7a\u65b9\u6848\u3002<\/p>\n<h3 id=\"1-%e6%9c%ac%e5%9c%b0%e6%95%b8%e6%93%9a%e5%ba%ab-jDTUpXyrhF\">1. \u672c\u5730\u6578\u64da\u5eab<\/h3>\n<p>UniApp \u63d0\u4f9b\u4e86\u5c0d\u672c\u5730\u6578\u64da\u5eab\u7684\u652f\u6301\uff0c\u901a\u5e38\u4f7f\u7528 <code>uni.setStorage<\/code> \u548c <code>uni.getStorage<\/code> \u4f86\u9032\u884c\u6578\u64da\u7684\u5b58\u53d6\u3002\u9019\u4e9b\u65b9\u6cd5\u9069\u5408\u5b58\u5132\u5c0f\u578b\u6578\u64da\uff0c\u5982\u7528\u6236\u8a2d\u7f6e\u6216\u61c9\u7528\u72c0\u614b\u3002<\/p>\n<pre><code>uni.setStorage({\n    key: 'userInfo',\n    data: {\n        name: 'John Doe',\n        age: 30\n    },\n    success: function () {\n        console.log('\u6578\u64da\u5b58\u5132\u6210\u529f');\n    }\n});\n\nuni.getStorage({\n    key: 'userInfo',\n    success: function (res) {\n        console.log('\u7372\u53d6\u7684\u6578\u64da:', res.data);\n    }\n});\n<\/code><\/pre>\n<h3 id=\"2-%e9%81%a0%e7%a8%8b%e6%95%b8%e6%93%9a%e5%ba%ab-jDTUpXyrhF\">2. \u9060\u7a0b\u6578\u64da\u5eab<\/h3>\n<p>\u5c0d\u65bc\u9700\u8981\u8655\u7406\u5927\u91cf\u6578\u64da\u7684\u61c9\u7528\uff0c\u4f7f\u7528\u9060\u7a0b\u6578\u64da\u5eab\u662f\u66f4\u70ba\u5408\u9069\u7684\u9078\u64c7\u3002\u958b\u767c\u8005\u53ef\u4ee5\u901a\u904e API \u8207\u5f8c\u7aef\u670d\u52d9\u9032\u884c\u4ea4\u4e92\uff0c\u5e38\u898b\u7684\u6578\u64da\u5eab\u5305\u62ec MySQL\u3001MongoDB \u7b49\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528 <code>uni.request<\/code> \u65b9\u6cd5\u9032\u884c\u9060\u7a0b\u6578\u64da\u5eab\u64cd\u4f5c\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>uni.request({\n    url: 'https:\/\/api.example.com\/getUserData',\n    method: 'GET',\n    success: function (res) {\n        console.log('\u7528\u6236\u6578\u64da:', res.data);\n    },\n    fail: function (err) {\n        console.error('\u8acb\u6c42\u5931\u6557:', err);\n    }\n});\n<\/code><\/pre>\n<h2 id=\"%e6%95%b8%e6%93%9a%e5%ba%ab%e6%93%8d%e4%bd%9c%e7%9a%84%e6%9c%80%e4%bd%b3%e5%af%a6%e8%b8%90-jDTUpXyrhF\">\u6578\u64da\u5eab\u64cd\u4f5c\u7684\u6700\u4f73\u5be6\u8e10<\/h2>\n<p>\u5728\u9032\u884c\u6578\u64da\u5eab\u64cd\u4f5c\u6642\uff0c\u9075\u5faa\u4e00\u4e9b\u6700\u4f73\u5be6\u8e10\u53ef\u4ee5\u63d0\u9ad8\u61c9\u7528\u7684\u6027\u80fd\u548c\u5b89\u5168\u6027\uff1a<\/p>\n<ul>\n<li><strong>\u6578\u64da\u9a57\u8b49\uff1a<\/strong>\u5728\u5c07\u6578\u64da\u5b58\u5165\u6578\u64da\u5eab\u4e4b\u524d\uff0c\u52d9\u5fc5\u9032\u884c\u9a57\u8b49\uff0c\u4ee5\u9632\u6b62\u4e0d\u6b63\u78ba\u6216\u60e1\u610f\u6578\u64da\u7684\u5b58\u5165\u3002<\/li>\n<li><strong>\u932f\u8aa4\u8655\u7406\uff1a<\/strong>\u5728\u9032\u884c API \u8acb\u6c42\u6642\uff0c\u61c9\u8a72\u59a5\u5584\u8655\u7406\u932f\u8aa4\u60c5\u6cc1\uff0c\u4e26\u63d0\u4f9b\u7528\u6236\u53cb\u597d\u7684\u932f\u8aa4\u63d0\u793a\u3002<\/li>\n<li><strong>\u6578\u64da\u52a0\u5bc6\uff1a<\/strong>\u5c0d\u65bc\u654f\u611f\u6578\u64da\uff0c\u61c9\u8003\u616e\u4f7f\u7528\u52a0\u5bc6\u6280\u8853\u4f86\u4fdd\u8b77\u7528\u6236\u96b1\u79c1\u3002<\/li>\n<li><strong>\u6027\u80fd\u512a\u5316\uff1a<\/strong>\u5c0d\u65bc\u983b\u7e41\u8a2a\u554f\u7684\u6578\u64da\uff0c\u8003\u616e\u4f7f\u7528\u7de9\u5b58\u6280\u8853\u4f86\u63d0\u9ad8\u6027\u80fd\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b5%90%e8%ab%96-jDTUpXyrhF\">\u7d50\u8ad6<\/h2>\n<p>\u5728 UniApp \u958b\u767c\u4e2d\uff0c\u6578\u64da\u5eab\u64cd\u4f5c\u662f\u4e0d\u53ef\u6216\u7f3a\u7684\u4e00\u90e8\u5206\u3002\u7121\u8ad6\u662f\u4f7f\u7528\u672c\u5730\u5b58\u5132\u9084\u662f\u9060\u7a0b\u6578\u64da\u5eab\uff0c\u958b\u767c\u8005\u90fd\u61c9\u8a72\u6839\u64da\u61c9\u7528\u7684\u9700\u6c42\u9078\u64c7\u5408\u9069\u7684\u89e3\u6c7a\u65b9\u6848\u3002\u901a\u904e\u9075\u5faa\u6700\u4f73\u5be6\u8e10\uff0c\u53ef\u4ee5\u78ba\u4fdd\u6578\u64da\u7684\u5b89\u5168\u6027\u548c\u61c9\u7528\u7684\u6027\u80fd\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u53ef\u9760\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\u4f86\u652f\u6301\u60a8\u7684 UniApp \u958b\u767c\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u6eff\u8db3\u4e0d\u540c\u9700\u6c42\u7684\u958b\u767c\u8005\u3002\u7121\u8ad6\u662f\u9700\u8981\u9ad8\u6027\u80fd\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2f\u4f3a\u670d\u5668<\/a> \u9084\u662f\u9748\u6d3b\u7684 <a href=\"https:\/\/server.hk\">\u96f2\u4f3a\u670d\u5668<\/a>\uff0c\u6211\u5011\u90fd\u80fd\u70ba\u60a8\u63d0\u4f9b\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22 UniApp \u958b\u767c\u4e2d\u7684\u6578\u64da\u5eab\u64cd\u4f5c\u6307\u5357\uff0c\u5b78\u7fd2\u5982\u4f55\u9ad8\u6548\u7ba1\u7406\u548c\u4f7f\u7528\u6578\u64da\u5eab\uff0c\u63d0\u5347\u61c9\u7528\u6027\u80fd\u8207\u7528\u6236\u9ad4\u9a57\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-168869","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/168869","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=168869"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/168869\/revisions"}],"predecessor-version":[{"id":168870,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/168869\/revisions\/168870"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=168869"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=168869"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=168869"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}