{"id":1799,"date":"2022-07-18T04:26:48","date_gmt":"2022-07-17T20:26:48","guid":{"rendered":"http:\/\/cheng-bing.top\/?p=1799"},"modified":"2022-07-18T04:26:48","modified_gmt":"2022-07-17T20:26:48","slug":"vue%e5%9f%ba%e7%a1%80%e6%95%99%e7%a8%8b%e7%ac%94%e8%ae%b0","status":"publish","type":"post","link":"https:\/\/cheng-bing.top\/index.php\/2022\/07\/18\/vue%e5%9f%ba%e7%a1%80%e6%95%99%e7%a8%8b%e7%ac%94%e8%ae%b0\/","title":{"rendered":"Vue\u57fa\u7840\u6559\u7a0b&#038;\u7b14\u8bb0"},"content":{"rendered":"\n<p>Project: https:\/\/github.com\/Harold-y\/Vue-Tutorial<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img   class=\"lazyload\" data-src=\"https:\/\/user-images.githubusercontent.com\/68500948\/178519179-e087c9c2-cd8b-4d11-a0da-0e4d0eb506db.png\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/Fuukei\/Public_Repository@latest\/vision\/load_svg\/inload.svg\" onerror=\"imgError(this)\"  alt=\"image\"\/><\/figure >\n<noscript><img src=\"https:\/\/user-images.githubusercontent.com\/68500948\/178519179-e087c9c2-cd8b-4d11-a0da-0e4d0eb506db.png\" alt=\"image\"\/><\/figure><\/noscript>\n\n\n\n<h2>Vue \u5e38\u7528\u547d\u4ee4<\/h2>\n\n\n\n<p>\u5b89\u88c5Vue\u811a\u624b\u67b6\uff08Cli\uff09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>npm install -g @vue\/cli\n<\/code><\/pre>\n\n\n\n<p>\u521b\u5efa\u65b0\u9879\u76ee<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vue create &lt;project-name&gt;\n<\/code><\/pre>\n\n\n\n<p>\u542f\u52a8Dev Server<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>npm run serve\n<\/code><\/pre>\n\n\n\n<p>\u542f\u52a8Json-Server<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>npx json-server --watch data\/db.json\n<\/code><\/pre>\n\n\n\n<h2><a href=\"https:\/\/github.com\/Harold-y\/Vue-Tutorial#%E5%87%A0%E4%B8%AA%E9%87%8D%E8%A6%81vue%E6%9D%BF%E5%9D%97\" target=\"_blank\"  rel=\"nofollow\" ><\/a>\u51e0\u4e2a\u91cd\u8981Vue\u677f\u5757<\/h2>\n\n\n\n<h3><a href=\"https:\/\/github.com\/Harold-y\/Vue-Tutorial#data\" target=\"_blank\"  rel=\"nofollow\" ><\/a>data<\/h3>\n\n\n\n<p>data\u677f\u5757\u7528\u4e8e\u5b58\u50a8\u6570\u636e\uff0c\u4e0b\u4f8b\u4e2d\uff0c\u6211\u4eec\u5728.env\u8bbe\u7f6eEndpoint\u8def\u5f84\u5e76\u4e14\u5728data\u4e2d\u5b9a\u4e49\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>data() {\n    return {\n      BASE_URL: process.env.VUE_APP_BASEURL,\n      jobs: &#91;],\n    }\n  },\n<\/code><\/pre>\n\n\n\n<h3><a href=\"https:\/\/github.com\/Harold-y\/Vue-Tutorial#props\" target=\"_blank\"  rel=\"nofollow\" ><\/a>props<\/h3>\n\n\n\n<p>props\u677f\u5757\u7528\u4e8e\u63a5\u53d7\u53c2\u6570\uff0c\u5305\u62ec\u901a\u8fc7\u6807\u7b7e\u4f20\u8fdb\u6765\u7684\u6216\u8005\u901a\u8fc7route\u53c2\u6570\u4f20\u8fdb\u6765\u7684\u3002 Case1: \u901a\u8fc7\u6807\u7b7e\u4f5c\u4e3a\u53c2\u6570\u4f20\u5165\uff0c\u4e0b\u4f8b\u4e2d\uff0c:reactionTime\u4f5c\u4e3a\u7ed1\u5b9a\u53c2\u6570\u4f20\u5165ResultVue componenet<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;ResultsVue v-if=\"showResults\" :reactionTime=\"score\"&gt;&lt;\/ResultsVue&gt;\n<\/code><\/pre>\n\n\n\n<p>Case2\uff1a\u4f5c\u4e3aRoute\u53c2\u6570\u4f20\u5165\uff0c\u4e0b\u4f8b\u4e2d\uff0c\u4f20\u5165\u540d\u4e3a'id'\u7684\u53c2\u6570<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;router-link :to=\"{ name: 'jobDetails', params: { id: job.id } }\"&gt;\n    &lt;h2&gt;{{ job.title }}&lt;\/h2&gt;\n&lt;\/router-link&gt;\n<\/code><\/pre>\n\n\n\n<p>\u8fd9\u79cd\u65b9\u6cd5\u4f20\u53c2\u9700\u8981\u5728router\u7684index.js enable\uff0c\u5982\u4e0b\u4f8b props: true<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n    path: \"\/jobs\/:id\",\n    name: \"jobDetails\",\n    component: JobDetails,\n    props: true, \/\/ can accept route parameter as props\n  },\n<\/code><\/pre>\n\n\n\n<h3><a href=\"https:\/\/github.com\/Harold-y\/Vue-Tutorial#methods\" target=\"_blank\"  rel=\"nofollow\" ><\/a>methods<\/h3>\n\n\n\n<p>methods\u5b9a\u4e49\u51fd\u6570<\/p>\n\n\n\n<h3><a href=\"https:\/\/github.com\/Harold-y\/Vue-Tutorial#computed\" target=\"_blank\"  rel=\"nofollow\" ><\/a>computed<\/h3>\n\n\n\n<p>computed\u5b9a\u4e49\u51fd\u6570\uff0c\u7528\u5df2\u6709\u7684\u5185\u5bb9\u8ba1\u7b97\u4e00\u4e2a\u65b0\u503creturn<\/p>\n\n\n\n<h3><a href=\"https:\/\/github.com\/Harold-y\/Vue-Tutorial#name\" target=\"_blank\"  rel=\"nofollow\" ><\/a>name<\/h3>\n\n\n\n<p>name\u662f\u540d\u79f0<\/p>\n\n\n\n<h3><a href=\"https:\/\/github.com\/Harold-y\/Vue-Tutorial#hooks\" target=\"_blank\"  rel=\"nofollow\" ><\/a>hooks<\/h3>\n\n\n\n<p><a href=\"https:\/\/vuejs.org\/guide\/essentials\/lifecycle.html#lifecycle-diagram\" target=\"_blank\"  rel=\"nofollow\" >https:\/\/vuejs.org\/guide\/essentials\/lifecycle.html#lifecycle-diagram<\/a>&nbsp;\u6839\u636e\u4e0d\u540c\u7684Lifecycle\u6709\u4e0d\u540c\u7684\u94a9\u5b50\uff0c\u6700\u5e38\u7528\u7684\u6709mounted()\uff0cupdated()\uff0cunmounted()\u4e09\u4e2a\u3002mounted()\u6700\u9002\u5408\u4f5c\u4e3ainitialization\u83b7\u53d6\u6570\u636e\u3002<\/p>\n\n\n\n<p>mounted()\u4f8b\u5b50\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mounted() {\n    fetch(this.BASE_URL + \"\/jobs\").then(res =&gt; res.json()).then(data =&gt; this.jobs = data).catch(err =&gt; console.log(err.message))\n  }\n<\/code><\/pre>\n\n\n\n<h2><a href=\"https:\/\/github.com\/Harold-y\/Vue-Tutorial#%E5%AE%9A%E4%B9%89%E5%85%A8%E5%B1%80%E5%8F%98%E9%87%8F\" target=\"_blank\"  rel=\"nofollow\" ><\/a>\u5b9a\u4e49\u5168\u5c40\u53d8\u91cf<\/h2>\n\n\n\n<p>\u5728\u6839\u76ee\u5f55\u521b\u5efa.env\u6587\u4ef6\uff0c\u53d8\u91cf\u547d\u540d\u65b9\u5f0f\u4e3aVUE_APPxxx\uff0c\u4f8b\u5982<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>VUE_APP_BASEURL = \"http:\/\/localhost:3000\"\n<\/code><\/pre>\n\n\n\n<p>\u83b7\u53d6\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>BASE_URL: process.env.VUE_APP_BASEURL\n<\/code><\/pre>\n\n\n\n<h2><a href=\"https:\/\/github.com\/Harold-y\/Vue-Tutorial#%E6%A0%87%E7%AD%BEvue-etc\" target=\"_blank\"  rel=\"nofollow\" ><\/a>\u6807\u7b7e+vue, etc.<\/h2>\n\n\n\n<h3><a href=\"https:\/\/github.com\/Harold-y\/Vue-Tutorial#%E5%8A%A8%E6%80%81%E6%98%BE%E7%A4%BAdata\" target=\"_blank\"  rel=\"nofollow\" ><\/a>\u52a8\u6001\u663e\u793adata<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>{{ &lt;data_name&gt; }}\n<\/code><\/pre>\n\n\n\n<h3><a href=\"https:\/\/github.com\/Harold-y\/Vue-Tutorial#v-on-or-%E5%92%8C%E5%85%B6%E5%AE%83%E4%BA%8B%E4%BB%B6\" target=\"_blank\"  rel=\"nofollow\" ><\/a>v-on: or @\u548c\u5176\u5b83\u4e8b\u4ef6<\/h3>\n\n\n\n<p>@\u662fv-on:\u7f29\u5199\uff0c\u591a\u7528\u4e8e\u548cButton\u7ed1\u5b9a\u521b\u5efa\u70b9\u51fb\u4e8b\u4ef6\u7ed1\u5b9a\u51fd\u6570\u3002\u4f8b\u5982\uff1a\uff08\u8bf7\u6ce8\u610f\uff0c\u4e0b\u4f8b\u4f7f\u7528\u4e86\u540d\u4e3a'isPlaying'\u7684variable\u7ed1\u5b9a\u4e8e\u6309\u94ae\u7684diabled\u5c5e\u6027\uff09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;button @click=\"start\" :disabled=\"isPlaying\"&gt;play&lt;\/button&gt;\n<\/code><\/pre>\n\n\n\n<p>\u5982\u679c\u60f3\u8981\u70b9\u51fb\u4e8b\u4ef6\u53ea\u4f5c\u7528\u4e8e\u7236\u5143\u7d20\u800c\u4e0d\u5305\u542b\u4efb\u4f55\u5b50\u5143\u7d20\uff0c\u4f7f\u7528\"@click.self\"\u3002<\/p>\n\n\n\n<p>\u8fd8\u53ef\u4ee5trigger\u5176\u5b83\u952e\u76d8\u5c5e\u6027\uff0c\u5982\u4e0b\u4f8b\u4e2d\uff0c\u6309\u4e0balt+\u67d0\u952e\u8d77\u6765\u5c31\u4f1a\u89e6\u53d1\u540d\u4e3a'addSkill'\u7684\u51fd\u6570\u3002\u51fd\u6570\u7b2c\u4e00\u4e2a\u53c2\u6570\u9ed8\u8ba4\u4e3ae\uff08\u4e5f\u5c31\u662fevent\uff09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;input type=\"text\" v-model=\"tempSkill\" @keyup.alt=\"addSkill\"&gt;\n<\/code><\/pre>\n\n\n\n<p>\u51fd\u6570\u793a\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>addSkill(e) {\n    if (e.key === ',' &amp;&amp; this.tempSkill) {\n        if (!this.skills.includes(this.tempSkill))\n            {\n                this.skills.push(this.tempSkill)\n            }\n        this.tempSkill = ''\n    }\n}\n<\/code><\/pre>\n\n\n\n<h3><a href=\"https:\/\/github.com\/Harold-y\/Vue-Tutorial#v-if%E5%92%8Cv-show\" target=\"_blank\"  rel=\"nofollow\" ><\/a>v-if\u548cv-show<\/h3>\n\n\n\n<p>\u90fd\u53ef\u4ee5\u5b9e\u73b0\u9690\u85cf\u5143\u7d20\u7684\u6548\u679c\uff0c\u4f46\u662fv-if\u662f\u52a8\u6001\u6dfb\u52a0\/\u79fb\u9664\uff0cv-show\u4ec5\u4ec5\u6539\u53d8\u5143\u7d20\u4e3a\u9690\u5f62\uff0c\u4ecd\u5b58\u5728\u4e8edom\u4e2d<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;div class=\"block\" v-if=\"showBlock\" @click=\"stopTimer\"&gt;\n    click me\n&lt;\/div&gt;\n<\/code><\/pre>\n\n\n\n<p>v-if\u540e\u53ef\u4ee5\u8ddf\u968f\u540c\u7b49\u7ea7v-else\u6807\u7b7e\uff0c\u5728if\u4e3afalse\u7684\u65f6\u5019\u663e\u793a<\/p>\n\n\n\n<h3><a href=\"https:\/\/github.com\/Harold-y\/Vue-Tutorial#v-bind%E5%92%8Cv-model\" target=\"_blank\"  rel=\"nofollow\" ><\/a>v-bind\u548cv-model<\/h3>\n\n\n\n<p>v-model\u57fa\u4e8e\u8868\u5355\u6570\u636e\u5b9e\u884c\u53cc\u5411\u7ed1\u5b9a\uff0c\u800cv-bind\u53ef\u4f5c\u7528\u4e8e\u8868\u5355\u5916\u3002 \u793a\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;input type=\"email\" required v-model=\"email\"\/&gt;\n<\/code><\/pre>\n\n\n\n<p>\u4e0b\u4f8b\u4e2d\u540d\u4e3a'role'\u7684variable\u4f1a\u83b7\u5f97\u9009\u62e9\u4e2dvalue\u7684\u503c\uff0c\u540c\u65f6\u53ef\u4ee5\u6307\u5b9a'role'\u521d\u59cb\u503c\uff0c\u8fd9\u6837select\u4f1a\u81ea\u52a8\u521d\u59cb\u9009\u4e2d\u90a3\u4e2aoption<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;select v-model=\"role\"&gt;\n    &lt;option value=\"developer\"&gt;Web Developer&lt;\/option&gt;\n    &lt;option value=\"designer\"&gt;Web Designer&lt;\/option&gt;\n    &lt;option value=\"janitor\"&gt;Janitor&lt;\/option&gt;\n&lt;\/select&gt;\n<\/code><\/pre>\n\n\n\n<p>\u9664\u4e86\u4e0a\u9762\u7684\u4f8b\u5b50\u5916\uff0cv-model\u7ed1\u5b9a\u5355\u4e2acheckbox\u4f1a\u4e3aboolean\uff1b\u7ed1\u5b9a\u591a\u4e2acheckbox\u9700\u8981\u7528array\u627f\u63a5\uff0c\u4f1a\u628a\u9009\u4e2d\u7684checkbox\u7684value\u6dfb\u52a0\u5230array<\/p>\n\n\n\n<h3><a href=\"https:\/\/github.com\/Harold-y\/Vue-Tutorial#%E5%8A%A8%E6%80%81class\" target=\"_blank\"  rel=\"nofollow\" ><\/a>\u52a8\u6001Class<\/h3>\n\n\n\n<p>\u8bed\u6cd5\u662f:class=\"{ &lt;class_name&gt; : }\" \u4f8b\u5982<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;div :class=\"{ sale: theme === 'sale' }\" \/&gt; \n<\/code><\/pre>\n\n\n\n<h2><a href=\"https:\/\/github.com\/Harold-y\/Vue-Tutorial#%E8%AE%BE%E7%BD%AE%E8%B7%AF%E7%94%B1\" target=\"_blank\"  rel=\"nofollow\" ><\/a>\u8bbe\u7f6e\u8def\u7531<\/h2>\n\n\n\n<h3><a href=\"https:\/\/github.com\/Harold-y\/Vue-Tutorial#%E6%99%AE%E9%80%9A%E8%B7%AF%E7%94%B1%E6%B3%A8%E5%86%8C\" target=\"_blank\"  rel=\"nofollow\" ><\/a>\u666e\u901a\u8def\u7531\u6ce8\u518c<\/h3>\n\n\n\n<p>\u9700\u8981\u5728index.js\u5148import\uff0c\u7136\u540e\u5982\u4e0b\u4f8b\u8fdb\u884c\u4f7f\u7528\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n    path: \"\/\",\n    name: \"home\",\n    component: HomeView,\n}\n<\/code><\/pre>\n\n\n\n<h3><a href=\"https:\/\/github.com\/Harold-y\/Vue-Tutorial#%E6%9F%90%E4%B8%AA%E8%B7%AF%E5%BE%84a%E9%87%8D%E5%AE%9A%E5%90%91%E5%88%B0%E5%88%AB%E7%9A%84%E5%9C%B0%E6%96%B9b\" target=\"_blank\"  rel=\"nofollow\" ><\/a>\u67d0\u4e2a\u8def\u5f84\uff08a\uff09\u91cd\u5b9a\u5411\u5230\u522b\u7684\u5730\u65b9\uff08b\uff09<\/h3>\n\n\n\n<p>\u4e0b\u4f8b\u4e2d\uff0c\u628a\/all-jobs\u8def\u5f84\u91cd\u5b9a\u5411\u5230\/jobs<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ redirect\n  {\n    path: \"\/all-jobs\",\n    redirect: \"\/jobs\",\n  }\n<\/code><\/pre>\n\n\n\n<h3><a href=\"https:\/\/github.com\/Harold-y\/Vue-Tutorial#%E6%8A%8A%E9%92%88%E5%AF%B9%E6%B2%A1%E6%9C%89%E5%87%BA%E7%8E%B0%E8%B7%AF%E7%94%B1%E7%9A%84%E8%AE%BF%E9%97%AE%E9%87%8D%E5%AE%9A%E5%90%91%E5%88%B0404%E7%95%8C%E9%9D%A2\" target=\"_blank\"  rel=\"nofollow\" ><\/a>\u628a\u9488\u5bf9\u6ca1\u6709\u51fa\u73b0\u8def\u7531\u7684\u8bbf\u95ee\u91cd\u5b9a\u5411\u5230404\u754c\u9762<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ catchall 404\n  {\n    path: \"\/:catchAll(.*)\", \/\/ regex, catch all that does not match any of the above\n    name: \"Not Found\",\n    component: NotFound,\n  }\n<\/code><\/pre>\n\n\n\n<h3><a href=\"https:\/\/github.com\/Harold-y\/Vue-Tutorial#%E8%AF%A6%E6%83%85%E9%A1%B5%E9%80%9A%E8%BF%87%E8%B7%AF%E7%94%B1id%E8%AE%BF%E9%97%AE\" target=\"_blank\"  rel=\"nofollow\" ><\/a>\u8be6\u60c5\u9875\u901a\u8fc7\u8def\u7531id\u8bbf\u95ee<\/h3>\n\n\n\n<p>\u4e0b\u4f8b\u4e2d\uff0c\u6211\u4eec\u901a\u8fc7jobs\/id\uff08\u7ed1\u5b9aid\uff09\u7684\u5f62\u5f0f\u6765\u8bbf\u95eejob detail\uff0c\u4f8b\u5982jobs\/1<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n    path: \"\/jobs\/:id\",\n    name: \"jobDetails\",\n    component: JobDetails,\n    props: true, \/\/ can accept route parameter as props\n}\n\n&lt;router-link :to=\"{ name: 'jobDetails', params: { id: job.id } }\"&gt;\n    &lt;h2&gt;{{ job.title }}&lt;\/h2&gt;\n&lt;\/router-link&gt;\n<\/code><\/pre>\n\n\n\n<p>\u6211\u4eec\u5728\u4e0a\u6587\u5199\u5230\u8fc7\uff0c\u6211\u4eec\u9700\u8981\u901a\u8fc7props\u6765\u63a5\u53d7id\u53c2\u6570<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>props: &#91;'id']\n<\/code><\/pre>\n\n\n\n<h3><a href=\"https:\/\/github.com\/Harold-y\/Vue-Tutorial#router-link\" target=\"_blank\"  rel=\"nofollow\" ><\/a>router-link<\/h3>\n\n\n\n<p>\u5982\u679c\u4f7f\u7528to\uff0c\u90a3\u4e48\u653e\u4e0apath\uff0c\u5982\u679c\u7528:to\uff0c\u90a3\u4e48\u8bf7\u7ed9\u4e88name\uff0c\u6709\u65f6\u8fd8\u9700\u8981params\uff08\u5982\u4e0a\u4f8b\uff09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;router-link to=\"\/\"&gt;Home&lt;\/router-link&gt; |\n&lt;router-link to=\"\/about\"&gt;About&lt;\/router-link&gt;\n&lt;router-link :to=\"{ name: 'jobs'}\"&gt;Jobs&lt;\/router-link&gt;\n<\/code><\/pre>\n\n\n\n<h3><a href=\"https:\/\/github.com\/Harold-y\/Vue-Tutorial#%E5%8F%91%E7%94%9F%E6%94%B9%E5%8F%98%E7%9A%84%E8%A7%86%E5%9B%BE\" target=\"_blank\"  rel=\"nofollow\" ><\/a>\u53d1\u751f\u6539\u53d8\u7684\u89c6\u56fe<\/h3>\n\n\n\n<p>router-view\uff0c\u4e00\u822c\u88ab\u653e\u5728App.vue\u4e2d<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;router-view&gt;&lt;\/router-view&gt;\n<\/code><\/pre>\n\n\n\n<h2><a href=\"https:\/\/github.com\/Harold-y\/Vue-Tutorial#%E4%BC%A0%E5%8F%82%E4%BC%A0%E5%87%BD%E6%95%B0\" target=\"_blank\"  rel=\"nofollow\" ><\/a>\u4f20\u53c2&amp;\u4f20\u51fd\u6570<\/h2>\n\n\n\n<h3><a href=\"https:\/\/github.com\/Harold-y\/Vue-Tutorial#%E4%BC%A0%E5%8F%82\" target=\"_blank\"  rel=\"nofollow\" ><\/a>\u4f20\u53c2<\/h3>\n\n\n\n<p>\u7236\u5143\u7d20\u653e\u7f6e\u5b50\u6807\u7b7e\u65f6\u4f7f\u7528':&lt;var_name&gt;'\uff0c\u4e0b\u4f8b\u4e2d\uff0c\u4f20\u5165\u540d\u4e3a'delay'\u7684\u53c2\u6570\uff0c\u53c2\u6570var\u662f\u7236\u5143\u7d20data\u4e2d\u540d\u4e3a'delay'\u7684\u90a3\u4e2a\uff08\u56e0\u4e3a\u4f7f\u7528\u4e86:\u8fdb\u884c\u7ed1\u5b9a\uff09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;BlockVue :delay=\"delay\" v-if=\"isPlaying\" @endTimer=\"endGame\"&gt;&lt;\/BlockVue&gt;\n<\/code><\/pre>\n\n\n\n<p>\u5b50\u5143\u7d20\u5728props\u4e2d\u63a5\u6536\u53c2\u6570<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>props: &#91;'delay']\n<\/code><\/pre>\n\n\n\n<h3><a href=\"https:\/\/github.com\/Harold-y\/Vue-Tutorial#%E4%BC%A0%E5%9B%9E%E8%B0%83%E5%87%BD%E6%95%B0%E4%BD%BF%E7%94%A8%E5%92%8Cthisemit\" target=\"_blank\"  rel=\"nofollow\" ><\/a>\u4f20\u56de\u8c03\u51fd\u6570\uff0c\u4f7f\u7528@\u548cthis.$emit<\/h3>\n\n\n\n<p>\u8fd8\u662f\u4e0a\u9762\u7684BlockVue\u4f8b\u5b50\uff0c\u5728BlockVue\u4e2d\u5b9a\u4e49\u4e0b\u9762\u7684\u51fd\u6570\uff0c\u5219\u4e0b\u9762\u51fd\u6570\u6267\u884c\u65f6\u901a\u8fc7this.$emit\u8c03\u7528\u7236\u5143\u7d20\u540d\u4e3a\"endGame\"\u7684\u51fd\u6570\uff0c\u5e76\u4e14\u5c06\u5b50\u5143\u7d20\"reactionTime\"\u53d8\u91cf\u4f5c\u4e3a\u7236\u5143\u7d20\"endGame\"\u51fd\u6570\u7b2c\u4e00\u4e2aparam\u3002\u7b80\u800c\u8a00\u4e4b\uff0c\u901a\u8fc7this.$emit\u8c03\u7528\u7236\u5143\u7d20\u7684\u4e00\u4e2a\u51fd\u6570\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>stopTimer() {\n    clearInterval(this.timer)\n    this.$emit('endTimer', this.reactionTime)\n}\n<\/code><\/pre>\n\n\n\n<h2><a href=\"https:\/\/github.com\/Harold-y\/Vue-Tutorial#style-scope\" target=\"_blank\"  rel=\"nofollow\" ><\/a>Style Scope<\/h2>\n\n\n\n<p>\u5728&lt;style&gt;\u5b9a\u4e49\u7684\u7c7b\u548c\u6807\u7b7e\u6837\u5f0f\u4f1a\u88ab\u4f5c\u7528\u4e8e\u5168\u5c40\uff0c\u60f3\u8981\u5c40\u9650\u4e8e\u7ec4\u4ef6\u5219\u4f7f\u7528<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;style scoped&gt;&lt;\/style&gt; \n<\/code><\/pre>\n\n\n\n<h2><a href=\"https:\/\/github.com\/Harold-y\/Vue-Tutorial#slot-%E6%A8%A1%E6%9D%BF\" target=\"_blank\"  rel=\"nofollow\" ><\/a>Slot \u6a21\u677f<\/h2>\n\n\n\n<p>\u5b50\u5143\u7d20\u5b9a\u4e49\u6807\u7b7e\uff0c\u5728\u7236\u5143\u7d20\u4f7f\u7528\u5b50\u5143\u7d20\u6807\u7b7e\u5f00\u5408\u5185\uff08\u4f8b\u5982\u4e2d\uff09\u4f20\u5165\u6765\u586b\u5145\u5bf9\u5e94\u7684\u6807\u7b7e \u4e0b\u4f8b\u4e2d\u7236\u5143\u7d20\u4f20\u8fdb\u53bb\u7684\u4f1a\u88ab\u586b\u5145\u4e8e\u5b50\u5143\u7d20\u9ed8\u8ba4\u7684\uff0c\u4f20\u5165\u7684name=links\u7684slot\u4f1a\u88ab\u586b\u5145\u4e8ev-slot:links<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;slot&gt;\n    xxx &lt;!-- This only show when no default slot is passed in--&gt;\n&lt;\/slot&gt;\n&lt;div class=\"actions\"&gt;\n    &lt;slot name=\"links\"&gt;&lt;\/slot&gt;\n&lt;\/div&gt;\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;ModalVue :header=\"header\" :text=\"text\" @close=\"toggleModal\" theme=\"sale\"&gt;\n    &lt;template v-slot:links&gt;\n        &lt;a href=\"#\" class=\"href\"&gt;sign up now&lt;\/a&gt;\n        &lt;a href=\"#\" class=\"href\"&gt;more info&lt;\/a&gt;\n    &lt;\/template&gt;\n    &lt;p&gt;Test slots&lt;\/p&gt;\n&lt;\/ModalVue&gt;\n<\/code><\/pre>\n\n\n\n<h2><a href=\"https:\/\/github.com\/Harold-y\/Vue-Tutorial#teleport\" target=\"_blank\"  rel=\"nofollow\" ><\/a>teleport<\/h2>\n\n\n\n<p>\u6807\u7b7e\u5c06\u91cc\u9762\u7684\u5143\u7d20\u6e32\u67d3\u5230\u4e0d\u540c\u4e8eid=\"app\"\u7684div\u4e2d\uff0c\u5982\u4e0b\u4f8b\u4f1a\u5c06\u6807\u7b7e\u6e32\u67d3\u5230id\u4e3amodals\u7684div\u4e2d\uff08\u8fd9\u4e9bdiv\u9700\u8981\u5728index.html\u4e2d\u51fa\u73b0\uff09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;teleport to=\"#modals\" v-if=\"showModal\"&gt;\n    &lt;a href=\"https:\/\/google.com&gt;Google&lt;\/a&gt;\n&lt;\/teleport&gt;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Project: https:\/\/github.com\/Harold-y\/Vue-Tutorial Vue \u5e38\u7528\u547d\u4ee4 \u5b89\u88c5Vue\u811a &#8230;<\/p>","protected":false},"author":1,"featured_media":1800,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[28],"tags":[],"_links":{"self":[{"href":"https:\/\/cheng-bing.top\/index.php\/wp-json\/wp\/v2\/posts\/1799"}],"collection":[{"href":"https:\/\/cheng-bing.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cheng-bing.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cheng-bing.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cheng-bing.top\/index.php\/wp-json\/wp\/v2\/comments?post=1799"}],"version-history":[{"count":1,"href":"https:\/\/cheng-bing.top\/index.php\/wp-json\/wp\/v2\/posts\/1799\/revisions"}],"predecessor-version":[{"id":1801,"href":"https:\/\/cheng-bing.top\/index.php\/wp-json\/wp\/v2\/posts\/1799\/revisions\/1801"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cheng-bing.top\/index.php\/wp-json\/wp\/v2\/media\/1800"}],"wp:attachment":[{"href":"https:\/\/cheng-bing.top\/index.php\/wp-json\/wp\/v2\/media?parent=1799"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cheng-bing.top\/index.php\/wp-json\/wp\/v2\/categories?post=1799"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cheng-bing.top\/index.php\/wp-json\/wp\/v2\/tags?post=1799"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}