{"id":303250,"date":"2021-01-17T08:12:19","date_gmt":"2021-01-17T00:12:19","guid":{"rendered":"http:\/\/4563.org\/?p=303250"},"modified":"2021-01-17T08:12:19","modified_gmt":"2021-01-17T00:12:19","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8-uniapp-%e4%b8%ad%e8%ae%bf%e9%97%ae-cabloyjs-%e5%90%8e%e7%ab%af%e7%ae%a1%e7%90%86%e7%b3%bb%e7%bb%9f-api","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=303250","title":{"rendered":"\u5982\u4f55\u5728 Uniapp \u4e2d\u8bbf\u95ee CabloyJS \u540e\u7aef\u7ba1\u7406\u7cfb\u7edf API"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u5982\u4f55\u5728 Uniapp \u4e2d\u8bbf\u95ee CabloyJS \u540e\u7aef\u7ba1\u7406\u7cfb\u7edf API               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zhennann <\/span>  <span><i><\/i> 3<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<h2>\u4ecb\u7ecd<\/h2>\n<p><code>CabloyJS<\/code>\u662f\u4e00\u6b3e\u514d\u8d39\u5f00\u6e90\u7684 NodeJS \u5168\u6808\u5f00\u53d1\u6846\u67b6\uff0c\u91c7\u7528\u524d\u540e\u7aef\u5206\u79bb\u8bbe\u8ba1\uff0c\u5177\u5907\u5f00\u7bb1\u5373\u7528\u7684\u540e\u53f0\u7ba1\u7406\u7cfb\u7edf<\/p>\n<p><code>Cabloy-SDK<\/code>\u662f\u4e13\u95e8\u4e3a Uniapp \u5e94\u7528\u91cf\u8eab\u5b9a\u5236\u7684\u524d\u7aef SDK\uff0c\u7528\u4e8e\u4fbf\u6377\u7684\u8bbf\u95ee CabloyJS \u63d0\u4f9b\u7684\u6240\u6709 API \u63a5\u53e3\uff0c\u8ba9 Uniapp \u524d\u7aef\u5f00\u53d1\u518d\u65e0<code>\u540e\u987e\u4e4b\u5fe7<\/code><\/p>\n<h2>\u7279\u6027<\/h2>\n<p>\u5404\u4e2a\u5e73\u53f0\u7684\u5c0f\u7a0b\u5e8f\u540e\u7aef API \u7cfb\u7edf\uff0c\u6700\u590d\u6742\u7684\u5c31\u662f\u8d26\u53f7\u4f53\u7cfb\u5bf9\u63a5\u3002CabloyJS \u63d0\u4f9b\u4e86\u4e00\u4e2a\u6a21\u5757\u5316\u7684\u751f\u6001\uff0c\u9700\u8981\u5f00\u53d1\u4ec0\u4e48\u5e73\u53f0\u4e0b\u7684\u5c0f\u7a0b\u5e8f\u5e94\u7528\uff0c\u53ea\u9700\u5b89\u88c5\u76f8\u5e94\u7684\u6a21\u5757\u5373\u53ef<\/p>\n<p>\u76ee\u524d<code>Cabloy-SDK<\/code>\u652f\u6301\u4ee5\u4e0b\u5e73\u53f0\u5c0f\u7a0b\u5e8f\u7684\u5f00\u7bb1\u5373\u7528\uff1a<\/p>\n<ol>\n<li>\u5fae\u4fe1\u5c0f\u7a0b\u5e8f<\/li>\n<li>\u4f01\u4e1a\u5fae\u4fe1\u5c0f\u7a0b\u5e8f<\/li>\n<li>\u9489\u9489\u5c0f\u7a0b\u5e8f<\/li>\n<\/ol>\n<h2>\u5982\u4f55\u4f7f\u7528 &#8211; \u524d\u7aef<\/h2>\n<h3>1. \u5bfc\u5165\u63d2\u4ef6<\/h3>\n<p>\u8fdb\u5165Uniapp \u63d2\u4ef6\u9875\u9762\uff0c\u70b9\u51fb\u6309\u94ae<code>\u4f7f\u7528 HBuilderX \u5bfc\u5165\u63d2\u4ef6<\/code>\uff0c\u5c06<code>Cabloy-SDK<\/code>\u63d2\u4ef6\u5bfc\u5165 Uniapp \u9879\u76ee\u4e2d<\/p>\n<blockquote>\n<p>\u5f3a\u70c8\u5efa\u8bae<code>\u4e0b\u8f7d\u793a\u4f8b\u9879\u76ee<\/code>\u67e5\u770b\u63d2\u4ef6\u7684\u57fa\u672c\u7528\u6cd5<\/p>\n<\/blockquote>\n<h3>2. \u4fee\u6539 main.js<\/h3>\n<p>\u5728<code>main.js<\/code>\u6587\u4ef6\u4e2d\u6dfb\u52a0\u5982\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre><code>import Vue from 'vue' import App from '.\/App'  import Cabloy from '.\/js_sdk\/cabloy-sdk'  \/\/ \u521d\u59cb\u5316 cabloy const cabloyOptions = {   base: {  scene: 'default',  locale: 'en-us',   },   api: {  baseURL: 'https:\/\/yourdomain.com',   }, }  Vue.prototype.$cabloy = Cabloy(Vue, cabloyOptions)  \/\/ \u767b\u5f55 Vue.prototype.$cabloy.util.login().then(res =&gt; {   \/\/ \u7531\u4e8e login \u662f\u7f51\u7edc\u8bf7\u6c42\uff0c\u53ef\u80fd\u4f1a\u5728 Page.onLoad \u4e4b\u540e\u624d\u8fd4\u56de   \/\/ \u6240\u4ee5\u6b64\u5904\u52a0\u5165 callback \u4ee5\u9632\u6b62\u8fd9\u79cd\u60c5\u51b5   if (Vue.prototype.$cabloy.__loginReadyCallback) {     Vue.prototype.$cabloy.__loginReadyCallback(res);   } }).catch(err =&gt; {   console.log(err) })  Vue.config.productionTip = false  App.mpType = 'app'  const app = new Vue({     ...App }) app.$mount() <\/code><\/pre>\n<blockquote>\n<ol>\n<li>\u9996\u5148\u8981\u521d\u59cb\u5316\u4e00\u4e2a<code>cabloy<\/code>\u5b9e\u4f8b\uff0c\u5e76\u4fdd\u5b58\u81f3 Vue.prototype.$cabloy\uff0c\u4fbf\u4e8e\u5728\u6240\u6709 Vue \u7ec4\u4ef6\u4e2d\u5f15\u7528<\/li>\n<li>\u5176\u6b21\u8c03\u7528<code>cabloy.util.login<\/code>\u8fdb\u884c\u767b\u5f55<\/li>\n<\/ol>\n<\/blockquote>\n<ul>\n<li>cabloyOptions<\/li>\n<\/ul>\n<table>\n<thead>\n<tr>\n<th>\u540d\u79f0<\/th>\n<th>\u8bf4\u660e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>base.scene<\/td>\n<td>\u5c0f\u7a0b\u5e8f\u573a\u666f\u540d\uff0c\u9ed8\u8ba4\u4e3a<code>default<\/code><\/td>\n<\/tr>\n<tr>\n<td>base.locale<\/td>\n<td>\u524d\u7aef\u9ed8\u8ba4\u4f7f\u7528\u7684\u8bed\u8a00<\/td>\n<\/tr>\n<tr>\n<td>api.baseURL<\/td>\n<td>\u540e\u7aef\u670d\u52a1\u7684 API \u5730\u5740<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<blockquote>\n<p><code>base.scene<\/code>\uff1aCabloyJS \u540e\u7aef\u53ef\u4ee5\u652f\u6301\u521b\u5efa\u591a\u4e2a\u5c0f\u7a0b\u5e8f\uff0c\u524d\u7aef\u901a\u8fc7\u6b64\u53c2\u6570\u8bbe\u7f6e\u8981\u5bf9\u63a5\u7684\u5c0f\u7a0b\u5e8f\u573a\u666f\u540d\uff0c\u9ed8\u8ba4\u4e3a<code>default<\/code><\/p>\n<\/blockquote>\n<h3>3. API \u6e05\u5355<\/h3>\n<p>\u63d2\u4ef6<code>Cabloy-SDK<\/code>\u4e3b\u8981\u63d0\u4f9b\u4e86\u4ee5\u4e0b API \u7ec4\u4ef6<\/p>\n<table>\n<thead>\n<tr>\n<th>\u540d\u79f0<\/th>\n<th>\u8bf4\u660e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>cabloy<\/td>\n<td>\u6839\u5bf9\u8c61<\/td>\n<\/tr>\n<tr>\n<td>cabloy.util<\/td>\n<td>\u5de5\u5177\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td>cabloy.api<\/td>\n<td>\u8bbf\u95ee\u540e\u7aef API \u63a5\u53e3<\/td>\n<\/tr>\n<tr>\n<td>cabloy.data<\/td>\n<td>\u72b6\u6001\u6570\u636e\u5b58\u50a8<\/td>\n<\/tr>\n<tr>\n<td>cabloy.config<\/td>\n<td>\u914d\u7f6e\u53c2\u6570<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u5982\u4f55\u4f7f\u7528 &#8211; \u540e\u7aef<\/h2>\n<p>CabloyJS \u63d0\u4f9b\u4e86\u4e00\u4e2a\u6a21\u5757\u5316\u7684\u751f\u6001\uff0c\u9700\u8981\u5f00\u53d1\u4ec0\u4e48\u5e73\u53f0\u4e0b\u7684\u5c0f\u7a0b\u5e8f\u5e94\u7528\uff0c\u53ea\u9700\u5b89\u88c5\u76f8\u5e94\u7684\u6a21\u5757\u5373\u53ef<\/p>\n<h3>1. \u5fae\u4fe1\u5c0f\u7a0b\u5e8f<\/h3>\n<h3>2. \u4f01\u4e1a\u5fae\u4fe1\u5c0f\u7a0b\u5e8f<\/h3>\n<h3>3. \u9489\u9489\u5c0f\u7a0b\u5e8f<\/h3>\n<h2>\u76f8\u5173\u94fe\u63a5<\/h2>\n<ul>\n<li>\u5b98\u7f51: https:\/\/cabloy.com\/<\/li>\n<li>GitHub: https:\/\/github.com\/zhennann\/cabloy<\/li>\n<li>Cabloy-Uniapp \u5f00\u53d1\u6587\u6863<\/li>\n<\/ul><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>3<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5079873\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : qinxi <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u81ea\u95ee\u81ea\u7b54\u5f0f\u7684\u63a8\u5e7f @Livid                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5079874\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Livid <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @qinxi \u8c22\u8c22\u4e3e\u62a5\u3002<\/p>\n<p>\u8fd9\u4e2a\u4e3b\u9898\u5df2\u7ecf\u88ab\u79fb\u52a8\u5230 \/go\/promotions<\/p>\n<p>@zhennann \u8bf7\u9605\u8bfb V2EX \u7684\u8282\u70b9\u4f7f\u7528\u89c4\u5219\uff1a<\/p>\n<p>https:\/\/www.v2ex.com\/help\/node                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5079875\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : zhennann <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Livid Thanks\uff0cI see. \u8fd9\u7bc7\u6587\u7ae0\u5185\u5bb9\u5c5e\u4e8e\u201c\u5206\u4eab\u521b\u9020\u201d\uff0c\u4e0d\u8fc7\u6807\u9898\u786e\u6709\u4e0d\u59a5\uff0c\u540e\u7eed\u6ce8\u610f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5728 Uniapp \u4e2d\u8bbf\u95ee Ca&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/303250"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=303250"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/303250\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=303250"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=303250"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=303250"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}