{"id":566,"date":"2023-12-22T10:04:34","date_gmt":"2023-12-22T02:04:34","guid":{"rendered":"http:\/\/ericw.top\/?p=566"},"modified":"2023-12-22T10:42:24","modified_gmt":"2023-12-22T02:42:24","slug":"watch-%e4%be%a6%e5%90%ac%e5%99%a8%ef%bc%88%e7%9b%91%e8%a7%86%e5%99%a8%ef%bc%89","status":"publish","type":"post","link":"http:\/\/ericw.top\/?p=566","title":{"rendered":"watch \u4fa6\u542c\u5668\uff08\u76d1\u89c6\u5668\uff09"},"content":{"rendered":"<h1 id=\"toc-0\">watch \u4fa6\u542c\u5668\uff08\u76d1\u89c6\u5668\uff09<\/h1>\n<p><strong>\u4f5c\u7528\uff1a<\/strong> <strong>\u76d1\u89c6\u6570\u636e\u53d8\u5316<\/strong>\uff0c\u6267\u884c\u4e00\u4e9b \u4e1a\u52a1\u903b\u8f91 \u6216 \u5f02\u6b65\u64cd\u4f5c<\/p>\n<p><strong>\u8bed\u6cd5\uff1a<\/strong><\/p>\n<p>1\u3001<strong>\u7b80\u5355\u5199\u6cd5\uff1a<\/strong> \u7b80\u5355\u7c7b\u578b\u6570\u636e\uff0c\u76f4\u63a5\u76d1\u89c6<\/p>\n<pre><code class=\"prettyprint\"  class=\"language-html\">data:{\n    word:&#039;\u82f9\u679c&#039;,\n    obj:{\n        word:&#039;\u82f9\u679c&#039;\n    }\n}\uff0c<\/code><\/pre>\n<p>2\u3001<strong>\u5b8c\u6574\u5199\u6cd5\uff1a<\/strong>\u6dfb\u52a0\u989d\u5916\u914d\u7f6e<\/p>\n<pre><code class=\"prettyprint\"  class=\"language-html\">watch:{\n    \/\/\u8be5\u65b9\u6cd5\u4f1a\u5728\u6570\u636e\u53d8\u5316\u65f6\uff0c\u89e6\u53d1\u6267\u884c\n    \u6570\u636e\u5c5e\u6027\u540d(newValue,oldValue){\n        \u4e00\u4e9b\u4e1a\u52a1\u903b\u8f91\uff0c\u5f02\u6b65\u64cd\u4f5c\u3002\n    },\n    &#039;\u5bf9\u8c61.\u5c5e\u6027\u540d&#039;(newValue,oldValue){\n        \u4e00\u4e9b\u4e1a\u52a1\u903b\u8f91 \u6216 \u5f02\u6b65\u64cd\u4f5c\n    }\n}<\/code><\/pre>\n<h2 id=\"toc-1\">\u5b8c\u6574\u5199\u6cd5<\/h2>\n<p><code class=\"prettyprint\" >deep:true<\/code>\u5bf9\u590d\u6742\u7c7b\u578b\u6df1\u5ea6\u76d1\u89c6<br \/>\n<code class=\"prettyprint\" >immediate:true<\/code>\u521d\u59cb\u5316\u7acb\u523b\u6267\u884c\u4e00\u6b21<code class=\"prettyprint\" >handler<\/code>\u65b9\u6cd5<\/p>\n<p>\u200b       <\/p>\n<pre><code class=\"prettyprint\"  class=\"language-html\">watch: {\/\/ watch \u5b8c\u6574\u5199\u6cd5\n    \u6570\u636e\u5c5e\u6027\u540d: {\n        deep: true, \/\/ \u6df1\u5ea6\u76d1\u89c6\n        immediate: true, \/\/ \u662f\u5426\u7acb\u523b\u6267\u884c\u4e00\u6b21handler\n        handler (newValue) {\n            console.log(newValue)\n        }\n    }\n}<\/code><\/pre>\n<p>\u4f8b\uff1a\u7ffb\u8bd1\u5668  <strong>\u5b9e\u65f6\u76d1\u63a7\u8f93\u5165\u6846\u53d8\u5316  \u8bed\u8a00\u53d8\u5316<\/strong><\/p>\n<pre><code class=\"prettyprint\"  class=\"language-html\">  &lt;div id=&quot;app&quot;&gt;\n    &lt;!-- \u6761\u4ef6\u9009\u62e9\u6846 --&gt;\n    &lt;div class=&quot;query&quot;&gt;\n      &lt;span&gt;\u7ffb\u8bd1\u6210\u7684\u8bed\u8a00\uff1a&lt;\/span&gt;\n      &lt;select v-model=&quot;obj.lang&quot;&gt;\n        &lt;option value=&quot;italy&quot;&gt;\u610f\u5927\u5229&lt;\/option&gt;\n        &lt;option value=&quot;english&quot;&gt;\u82f1\u8bed&lt;\/option&gt;\n        &lt;option value=&quot;german&quot;&gt;\u5fb7\u8bed&lt;\/option&gt;\n      &lt;\/select&gt;\n    &lt;\/div&gt;\n\n    &lt;!-- \u7ffb\u8bd1\u6846 --&gt;\n    &lt;div class=&quot;box&quot;&gt;\n      &lt;div class=&quot;input-wrap&quot;&gt;\n        &lt;textarea v-model=&quot;obj.words&quot;&gt;&lt;\/textarea&gt;\n        &lt;span&gt;&lt;i&gt;\u2328\ufe0f&lt;\/i&gt;\u6587\u6863\u7ffb\u8bd1&lt;\/span&gt;\n      &lt;\/div&gt;\n      &lt;div class=&quot;output-wrap&quot;&gt;\n        &lt;div class=&quot;transbox&quot;&gt;{{ result }}&lt;\/div&gt;\n      &lt;\/div&gt;\n    &lt;\/div&gt;\n  &lt;\/div&gt;\n  &lt;script src=&quot;.\/vue.js&quot;&gt;&lt;\/script&gt;\n  &lt;script src=&quot;.\/axios.js&quot;&gt;&lt;\/script&gt;\n  &lt;script&gt;\n    \/\/ \u63a5\u53e3\u5730\u5740\uff1ahttps:\/\/applet-base-api-t.itheima.net\/api\/translate\n    \/\/ \u8bf7\u6c42\u65b9\u5f0f\uff1aget\n    \/\/ \u8bf7\u6c42\u53c2\u6570\uff1a\n    \/\/ \uff081\uff09words\uff1a\u9700\u8981\u88ab\u7ffb\u8bd1\u7684\u6587\u672c\uff08\u5fc5\u4f20\uff09\n    \/\/ \uff082\uff09lang\uff1a \u9700\u8981\u88ab\u7ffb\u8bd1\u6210\u7684\u8bed\u8a00\uff08\u53ef\u9009\uff09\u9ed8\u8ba4\u503c-\u610f\u5927\u5229\n    \/\/ -----------------------------------------------\n\n    const app = new Vue({\n      el: &#039;#app&#039;,\n      data: {\n        obj: {\n          words: &#039;\u8bf7\u8f93\u5165\u6587\u5b57&#039;,\n          lang: &#039;italy&#039;,\n        },\n        result: &#039;&#039;,\n      },\n      \/\/ \u5177\u4f53\u8bb2\u89e3\uff1a(1) watch\u8bed\u6cd5 (2) \u5177\u4f53\u4e1a\u52a1\u5b9e\u73b0\n      watch: {\n        obj: {\n          deep: true,\n          immediate: true,\n          handler(newVal) {\n            clearTimeout(this.timer)\n            this.timer = setTimeout(async () =&gt; {\n              const res = await axios({\n                url: &#039;https:\/\/applet-base-api-t.itheima.net\/api\/translate&#039;,\n                params: newVal\n              })\n              this.result = res.data.data\n            }, 300)\n          }\n        }\n      }\n    })\n  &lt;\/script&gt;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>watch \u4fa6\u542c\u5668\uff08\u76d1\u89c6\u5668\uff09 \u4f5c\u7528\uff1a \u76d1\u89c6\u6570\u636e\u53d8\u5316\uff0c\u6267\u884c\u4e00\u4e9b \u4e1a\u52a1\u903b\u8f91 \u6216 \u5f02\u6b65\u64cd\u4f5c \u8bed\u6cd5\uff1a 1\u3001\u7b80\u5355\u5199\u6cd5\uff1a  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":568,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17,5],"tags":[],"_links":{"self":[{"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts\/566"}],"collection":[{"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=566"}],"version-history":[{"count":2,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts\/566\/revisions"}],"predecessor-version":[{"id":569,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts\/566\/revisions\/569"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/media\/568"}],"wp:attachment":[{"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=566"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=566"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=566"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}