{"id":38,"date":"2025-06-09T00:25:29","date_gmt":"2025-06-08T16:25:29","guid":{"rendered":"https:\/\/www.bandifee.com\/?p=38"},"modified":"2025-06-09T00:26:09","modified_gmt":"2025-06-08T16:26:09","slug":"%e8%b0%83%e7%94%a8%e7%99%be%e5%ba%a6api%e7%bb%93%e5%90%88%e7%bf%bb%e8%af%91%e5%86%85%e5%ae%b9","status":"publish","type":"post","link":"https:\/\/blog.bandifee.com\/index.php\/2025\/06\/09\/%e8%b0%83%e7%94%a8%e7%99%be%e5%ba%a6api%e7%bb%93%e5%90%88%e7%bf%bb%e8%af%91%e5%86%85%e5%ae%b9\/","title":{"rendered":"\u8c03\u7528\u767e\u5ea6API\u7ed3\u5408\u7ffb\u8bd1\u5185\u5bb9"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u524d\u7aef\u4f7f\u7528Vue\u5411\u540e\u7aef\u53d1\u9001\u8bf7\u6c42<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code> const app = new Vue({\n    el: '#app',\n    data: {\n      words: '',\n      result: '',\n      timer: null,\n      to: 'en'\n    },\n    watch: {\n      async words(newValue) {\n        if (!newValue)\n        {\n          this.result = ''\n          return\n        }\n        clearTimeout(this.timer)\n        this.timer = setTimeout(async () => {\n          const res = await axios.get('.\/php\/P032_Translate.php', {\n            params: {\n              q: newValue,\n              from: 'auto',\n              to: this.to,\n            }\n          })\n          this.result = res.data.trans_result&#91;0].dst\n        }, 500)\n      },\n      async to(newTo) {\n        if (!this.words) {\n          this.result = ''\n          return\n        }\n        const res = await axios.get('.\/php\/P032_Translate.php', {\n          params: {\n            q: this.words,\n            from: 'auto',\n            to: newTo,\n          }\n        })\n        this.result = res.data.trans_result&#91;0].dst\n      }\n    }\n  })<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u540e\u7aef\u8fd4\u56de(\u90e8\u5206\u4ee3\u7801)<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>function translate($query, $from, $to)\n{\n    $args = array(\n        'q' => $query,\n        'appid' => APP_ID,\n        'salt' => rand(10000,99999),\n        'from' => $from,\n        'to' => $to,\n\n    );\n    $args&#91;'sign'] = buildSign($query, APP_ID, $args&#91;'salt'], SEC_KEY);\n    $ret = call(URL, $args);\n    $ret = json_decode($ret, true);\n    return $ret;\n}\n\n$q = $_GET&#91;'q'];\n$from = $_GET&#91;'from'];\n$to = $_GET&#91;'to'];\necho json_encode(translate($q, $from, $to));\nreturn;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u7aef\u4f7f\u7528Vue\u5411\u540e\u7aef\u53d1\u9001\u8bf7\u6c42 \u540e\u7aef\u8fd4\u56de(\u90e8\u5206\u4ee3\u7801)<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[6],"tags":[2,10],"class_list":["post-38","post","type-post","status-publish","format-standard","hentry","category-6","tag-php","tag-vue"],"_links":{"self":[{"href":"https:\/\/blog.bandifee.com\/index.php\/wp-json\/wp\/v2\/posts\/38","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.bandifee.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.bandifee.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.bandifee.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.bandifee.com\/index.php\/wp-json\/wp\/v2\/comments?post=38"}],"version-history":[{"count":1,"href":"https:\/\/blog.bandifee.com\/index.php\/wp-json\/wp\/v2\/posts\/38\/revisions"}],"predecessor-version":[{"id":39,"href":"https:\/\/blog.bandifee.com\/index.php\/wp-json\/wp\/v2\/posts\/38\/revisions\/39"}],"wp:attachment":[{"href":"https:\/\/blog.bandifee.com\/index.php\/wp-json\/wp\/v2\/media?parent=38"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.bandifee.com\/index.php\/wp-json\/wp\/v2\/categories?post=38"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.bandifee.com\/index.php\/wp-json\/wp\/v2\/tags?post=38"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}