{"id":9525,"date":"2023-11-23T18:34:06","date_gmt":"2023-11-23T10:34:06","guid":{"rendered":"https:\/\/www.yimenyun.cn\/emen\/?p=9525"},"modified":"2023-11-23T18:34:06","modified_gmt":"2023-11-23T10:34:06","slug":"%e5%b0%86%e7%bd%91%e9%a1%b5%e7%94%9f%e6%88%90%e7%9a%84app%e6%96%b9%e6%b3%95%e6%ad%a5%e9%aa%a4%e6%9c%89%e5%93%aa%e4%ba%9b","status":"publish","type":"post","link":"https:\/\/www.yimenyun.cn\/emen\/9525\/","title":{"rendered":"\u5c06\u7f51\u9875\u751f\u6210\u7684app\u65b9\u6cd5\u6b65\u9aa4\u6709\u54ea\u4e9b?"},"content":{"rendered":"

\u5c06\u7f51\u9875\u751f\u6210\u7684APP\uff08\u539f\u7406\u53ca\u8be6\u7ec6\u4ecb\u7ecd)<\/p>\n

\u5c06\u7f51\u9875\u751f\u6210\u7684APP\uff0c\u901a\u5e38\u79f0\u4e3aWeb APP\u6216\u8005\u6e10\u8fdb\u5f0fWeb\u5e94\u7528\uff08Progressive Web App\uff0c\u7b80\u79f0PWA\uff09\uff0c\u5177\u6709\u539f\u751fAPP\u7684\u7528\u6237\u4f53\u9a8c\u53ca\u529f\u80fd\uff0c\u4f46\u5374\u4e0d\u9700\u8981\u901a\u8fc7\u5e94\u7528\u5546\u5e97\u5b89\u88c5\u3002\u5b83\u57fa\u4e8eWeb\u6280\u672f\u8fdb\u884c\u5f00\u53d1\uff0c\u901a\u8fc7\u4e00\u7cfb\u5217\u4f18\u5316\u53ca\u589e\u52a0\u4e00\u4e9b\u73b0\u4ee3Web API\uff0c\u4f7f\u5f97\u7f51\u9875\u5e94\u7528\u8868\u73b0\u5f97\u66f4\u52a0\u63a5\u8fd1\u539f\u751fAPP\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5c06\u7f51\u9875\u751f\u6210\u7684APP\u80cc\u540e\u7684\u539f\u7406\u53ca\u5b9e\u73b0\u8fc7\u7a0b\u3002<\/p>\n

1\u624b\u673a\u751f\u6210\u7f51\u7ad9app<\/a>. \u6e10\u8fdb\u5f0fWeb\u5e94\u7528\uff08PWA\uff09\u7684\u6838\u5fc3\u6280\u672f<\/p>\n

1.1 Service Worker<\/p>\n

Service Worker\u662f\u4e00\u79cd\u8fd0\u884c\u5728\u6d4f\u89c8\u5668\u540e\u53f0\u7684JavaScript\u811a\u672c\uff0c\u53ef\u4ee5\u62e6\u622a\u548c\u63a7\u5236\u7f51\u7edc\u8bf7\u6c42\uff0c\u5b9e\u73b0\u7f13\u5b58\u3001\u79bb\u7ebf\u8bbf\u95ee\u3001\u6d88\u606f\u63a8\u9001\u7b49\u529f\u80fd\u3002Service Work\u7f51\u9875\u751f\u6210\u4e00\u952eapp<\/a>er\u72ec\u7acb\u4e8e\u7f51\u9875\uff0c\u53ef\u4ee5\u5728\u6d4f\u89c8\u5668\u5173\u95ed\u540e\u8fd0\u884c\uff0c\u4e0d\u4f1a\u963b\u585e\u4e3b\u7ebf\u7a0b\u3002<\/p>\n

1.2 Web App Manifest<\/p>\n

Web App Manifest \u662f\u4e00\u4e2aJSON\u6587\u4ef6\uff0c\u63d0\u4f9b\u4e86\u5173\u4e8eWeb APP\u7684\u5143\u6570\u636e\u4fe1\u606f\uff0c\u5982\u5e94\u7528\u540d\u79f0\u3001\u63cf\u8ff0\u3001\u56fe\u6807\u3001\u542f\u52a8\u9875\u7b49\u3002\u501f\u52a9\u8fd9\u4e9b\u4fe1\u606f\uff0c\u6d4f\u89c8\u5668\u53ef\u4ee5\u5c06\u7f51\u9875\u5e94\u7528\u5b89\u88c5\u5230\u8bbe\u5907\u684c\u9762\uff0c\u5e76\u63d0\u4f9b\u7c7b\u4f3c\u539f\u751fAPP\u7684\u542f\u52a8\u753b\u9762\u3002<\/p>\n

1.3 \u54cd\u5e94\u5f0f\u8bbe\u8ba1<\/p>\n

\u4e3a\u4e86\u9002\u5e94\u4e0d\u540c\u8bbe\u5907\u548c\u5c4f\u5e55\u5c3a\u5bf8\uff0cPWA\u5e94\u91c7\u7528\u54cd\u5e94\u5f0f\u8bbe\u8ba1\uff0c\u901a\u8fc7CSS\u5a92\u4f53\u67e5\u8be2\u786e\u4fdd\u5e94\u7528\u5728\u4e0d\u540c\u8bbe\u5907\u4e0a\u5177\u6709\u826f\u597d\u7684\u7528\u6237\u754c\u9762\u548c\u4f53\u9a8c\u3002<\/p>\n

2. \u5c06\u7f51\u9875\u751f\u6210APP\u7684\u6b65\u9aa4<\/p>\n

2.1 \u521b\u5efaService Worker<\/p>\n

\u9996\u5148\u9700\u8981\u7f16\u5199Service Worker\u811a\u672c\uff0c\u5b9e\u73b0\u8d44\u6e90\u7684\u7f13\u5b58\u53ca\u79bb\u7ebf\u8bbf\u95ee\u529f\u80fd\u3002\u7136\u540e\u5728\u7f51\u9875\u4e2d\u6ce8\u518cService Worker\uff0c\u4f7f\u5176\u751f\u6548\u3002<\/p>\n

2.2 \u6dfb\u52a0Web App Manifest<\/p>\n

\u521b\u5efa\u4e00\u4e2aJSON\u683c\u5f0f\u7684manifest\u6587\u4ef6\uff0c\u586b\u5199\u5e94\u7528\u7684\u5143\u6570\u636e\u4fe1\u606f\uff0c\u5e76\u5728HTML\u6587\u4ef6\u7684\u5934\u90e8\u5f15\u5165\u8be5\u6587\u4ef6\u3002<\/p>\n

“`<\/p>\n<\/p>\n

“`<\/p>\n

2.3 \u5b9e\u73b0\u54cd\u5e94\u5f0f\u8bbe\u8ba1<\/p>\n

\u4f7f\u7528CSS\u5a92\u4f53\u67e5\u8be2\u4e3a\u4e0d\u540c\u8bbe\u5907\u548c\u5c4f\u5e55\u5c3a\u5bf8\u7f16\u5199\u9002\u5e94\u6027\u6837\u5f0f\uff0c\u786e\u4fdd\u5e94\u7528\u7684\u7528\u6237\u754c\u9762\u5728\u5404\u79cd\u8bbe\u5907\u4e0a\u4fdd\u6301\u826f\u597d\u7684\u5e03\u5c40\u548c\u663e\u793a\u6548\u679c\u3002<\/p>\n

2.4 \u4f7f\u7528\u73b0\u4ee3Web API\u589e\u5f3a\u529f\u80fd<\/p>\n

\u6839\u636e\u9700\u8981\uff0c\u5b9e\u73b0\u6d88\u606f\u63a8\u9001\u3001\u8bbe\u5907\u9002\u914d\u3001\u652f\u4ed8\u7b49\u529f\u80fd\uff0c\u4f7f\u7f51\u9875\u5e94\u7528\u66f4\u52a0\u63a5\u8fd1\u539f\u751fAPP\u7684\u4f53\u9a8c\u3002<\/p>\n

2.5 \u6d4b\u8bd5\u53ca\u4f18\u5316<\/p>\n

\u5728\u5404\u79cd\u8bbe\u5907\u548c\u6d4f\u89c8\u5668\u4e0a\u6d4b\u8bd5\u5e94\u7528\uff0c\u786e\u4fdd\u517c\u5bb9\u6027\u548c\u6027\u80fd\uff0c\u4f18\u5316\u4efb\u4f55\u51fa\u73b0\u7684\u95ee\u9898\u3002<\/p>\n

3. PWA\u6846\u67b6\u4e0e\u5de5\u5177<\/p>\n

\u6709\u8bb8\u591a\u6210\u719f\u7684\u6846\u67b6\u548c\u5de5\u5177\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u66f4\u5feb\u901f\u7684\u5c06\u7f51\u9875\u751f\u6210APP\uff0c\u5982\uff1a<\/p>\n

3.1 Create React App<\/p>\n

\u4f7f\u7528React<\/p>\n

<\/figure>\n<\/p>\n

\u7684\u811a\u624b\u67b6\u5de5\u5177\uff0c\u53ef\u4ee5\u521b\u5efa\u652f\u6301PWA\u7684\u5e94\u7528\u3002<\/p>\n

3.2 Vue CLI<\/p>\n

\u91c7\u7528Vue.js\u7684\u5e94\u7528\u811a\u624b\u67b6\u5de5\u5177\uff0c\u53ef\u4ee5\u521b\u5efa\u652f\u6301PWA\u7684\u9879\u76ee\u3002<\/p>\n

3.3 Workbox<\/p>\n

Google\u63a8\u51fa\u7684\u4e00\u5957\u7528\u4e8e\u5904\u7406Service Worker\u7f13\u5b58\u7b56\u7565\u7684\u5e93\uff0c\u7b80\u5316\u5f00\u53d1\u8fc7\u7a0b\u3002<\/p>\n

\u901a\u8fc7\u4ee5\u4e0a\u8bf4\u660e\uff0c\u76f8\u4fe1\u4f60\u5bf9\u5c06\u7f51\u9875\u751f\u6210\u7684APP\u7684\u539f\u7406\u548c\u5b9e\u73b0\u6709\u4e86\u4e00\u4e2a\u5927\u81f4\u4e86\u89e3\u3002PWA\u5728\u63d0\u5347\u7528\u6237\u4f53\u9a8c\u7684\u540c\u65f6\uff0c\u51cf\u5c11\u4e86\u5f00\u53d1\u6210\u672c\u548c\u8de8\u5e73\u53f0\u517c\u5bb9\u6027\u95ee\u9898\uff0c\u503c\u5f97\u5f00\u53d1\u8005\u548c\u4f01\u4e1a\u5173\u6ce8\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5c06\u7f51\u9875\u751f\u6210\u7684APP\uff08\u539f\u7406\u53ca\u8be6\u7ec6\u4ecb\u7ecd)\u5c06\u7f51\u9875\u751f\u6210\u7684APP\uff0c\u901a\u5e38\u79f0\u4e3aWeb APP\u6216\u8005\u6e10\u8fdb\u5f0fWeb\u5e94\u7528\uff08Progressive Web App\uff0c\u7b80\u79f0PWA\uff09\uff0c\u5177\u6709\u539f\u751fAPP\u7684\u7528\u6237\u4f53\u9a8c\u53ca\u529f\u80fd\uff0c\u4f46\u5374\u4e0d\u9700\u8981\u901a<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[10229,259,15681,149,56],"topic":[],"class_list":{"0":"post-9525","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-appkf","7":"tag-app","8":"tag-259","10":"tag-149","11":"tag-56"},"_links":{"self":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/9525","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/comments?post=9525"}],"version-history":[{"count":1,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/9525\/revisions"}],"predecessor-version":[{"id":9630,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/9525\/revisions\/9630"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/media?parent=9525"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/categories?post=9525"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/tags?post=9525"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/topic?post=9525"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}