{"id":776,"date":"2021-08-13T11:00:40","date_gmt":"2021-08-13T03:00:40","guid":{"rendered":"https:\/\/fireinsect.top\/?p=776"},"modified":"2021-08-15T09:16:24","modified_gmt":"2021-08-15T01:16:24","slug":"vue%e7%bb%84%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/fireinsect.top\/index.php\/2021\/08\/13\/vue%e7%bb%84%e4%bb%b6\/","title":{"rendered":"Vue\u7ec4\u4ef6"},"content":{"rendered":"\n<p>\u7ec4\u4ef6\u5c31\u662f\u53ef\u590d\u7528\u7684Vue\u5b9e\u4f8b\uff0c\u5728\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u628a\u91cd\u590d\u4f7f\u7528\u7684\u529f\u80fd\u5c01\u88c5\u6210\u81ea\u5b9a\u4e49\u7ec4\u4ef6\uff0c\u4ee5\u8fbe\u5230\u4fbf\u6377\u5f00\u53d1\u7684\u76ee\u7684\u3002<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>\u901a\u5e38\u4e00\u4e2a\u5e94\u7528\u4f1a\u4ee5\u4e00\u68f5\u5d4c\u5957\u7684\u7ec4\u4ef6\u6811\u7684\u5f62\u5f0f\u6765\u7ec4\u7ec7\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/i2.wp.com\/document.youkeda.com\/P3-5-Vue\/5\/4.png?w=1170&#038;ssl=1\" alt=\"\" data-recalc-dims=\"1\"\/><\/figure>\n\n\n\n<p>\u4f60\u53ef\u80fd\u4f1a\u6709\u5934\u90e8\u5bfc\u822a\u3001\u5185\u5bb9\u533a\u3001\u4fa7\u8fb9\u680f\u7b49\u7ec4\u4ef6\uff0c\u6bcf\u4e2a\u7ec4\u4ef6\u5185\u90e8\u53c8\u5305\u542b\u4e86\u5bfc\u822a\u94fe\u63a5\u3001\u535a\u6587\u4e4b\u7c7b\u7684\u7ec4\u4ef6\u3002<\/p>\n\n\n\n<p>\u4e3a\u4e86\u80fd\u5728\u6a21\u677f &lt;template&gt; \u4e2d\u4f7f\u7528\uff0c\u8fd9\u4e9b\u7ec4\u4ef6\u5fc5\u987b\u5148\u6ce8\u518c\u4ee5\u4fbf Vue\u80fd\u591f\u8bc6\u522b\u3002<\/p>\n\n\n\n<div style=\"height:44px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-vivid-red-color has-text-color has-large-font-size\">\u7ec4\u4ef6\u7684\u6ce8\u518c<\/p>\n\n\n\n<p>\u5728 Vue \u4e2d\uff0c\u7ec4\u4ef6\u7684\u6ce8\u518c\u5206\u5168\u5c40\u6ce8\u518c\u548c\u5c40\u90e8\u6ce8\u518c\u4e24\u79cd\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>\u5168\u5c40\u6ce8\u518c\uff1a\u7528 <code>Vue.component <\/code>\u6765\u521b\u5efa\u7ec4\u4ef6\uff0c\u6ce8\u518c\u4e4b\u540e\u53ef\u4ee5\u5728\u4efb\u4f55\u65b0\u521b\u5efa\u7684 Vue \u6839\u5b9e\u4f8b\u4e2d\u4f7f\u7528\uff1b<\/li><li>\u5c40\u90e8\u6ce8\u518c\uff1a\u5728\u5355\u4e2a Vue \u683c\u5f0f\u7684\u6587\u4ef6\u4e2d\u521b\u5efa\u7ec4\u4ef6\uff0c\u5728\u9700\u8981\u7528\u5230\u7684\u5730\u65b9\u8fdb\u884c\u6ce8\u518c;<\/li><\/ol>\n\n\n\n<p>\u4f46\u901a\u5e38\u6211\u4eec\u90fd\u662f\u57fa\u4e8e Vue \u5de5\u7a0b\u8fdb\u884c\u5f00\u53d1\u7684\uff0c\u4f1a\u7528\u5230 webpack \u8fd9\u6837\u7684\u6784\u5efa\u7cfb\u7edf\uff0c\u800c\u901a\u8fc7\u5168\u5c40\u6ce8\u518c\u7684\u7ec4\u4ef6\u5728\u6784\u5efa\u7cfb\u7edf\u4e2d\u5373\u4f7f\u6ca1\u88ab\u4f7f\u7528\u4f9d\u7136\u4f1a\u5b58\u5728\u4e8e\u6784\u5efa\u7ed3\u679c\u4e2d\uff0c\u6240\u4ee5\u6211\u4eec\u901a\u5e38\u9009\u62e9\u5c40\u90e8\u6ce8\u518c\u3002<\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-vivid-red-color has-text-color has-medium-font-size\">\u7ec4\u4ef6\u7684\u521b\u5efa<\/p>\n\n\n\n<p>\u6bcf\u4e2aVue\u683c\u5f0f\u7684\u6587\u4ef6\u90fd\u53ef\u4ee5\u4f5c\u4e3a\u4e00\u4e2a\u7ec4\u4ef6\u6765\u4f7f\u7528<\/p>\n\n\n\n<p> <\/p>\n\n\n\n<p class=\"has-vivid-red-color has-text-color has-medium-font-size\">\u7ec4\u4ef6\u7684\u5c40\u90e8\u6ce8\u518c<\/p>\n\n\n\n<p>\u9996\u5148\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2aVue\u6587\u4ef6<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/i2.wp.com\/document.youkeda.com\/P3-5-Vue\/5\/1.png?w=1170&#038;ssl=1\" alt=\"\" data-recalc-dims=\"1\"\/><\/figure>\n\n\n\n<div style=\"height:62px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>\u7136\u540e\u9700\u8981\u5b9a\u4e49\u7ec4\u4ef6\u540d\u5b57<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/i1.wp.com\/document.youkeda.com\/P3-5-Vue\/5\/2.jpg?w=1170&#038;ssl=1\" alt=\"\" data-recalc-dims=\"1\"\/><\/figure>\n\n\n\n<div style=\"height:36px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>\u5728\u9700\u8981\u4f7f\u7528\u7684\u5730\u65b9\uff0c\u6ce8\u518c\u7ec4\u4ef6\u3001\u5f15\u5165\u7ec4\u4ef6\u4ee5\u53ca\u4f7f\u7528\u7ec4\u4ef6<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/i2.wp.com\/document.youkeda.com\/P3-5-Vue\/5\/3.jpg?w=1170&#038;ssl=1\" alt=\"\" data-recalc-dims=\"1\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size\">\u7ec4\u4ef6\u5185\u6570\u636edata\u5fc5\u987b\u662f\u4e00\u4e2a\u51fd\u6570<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\">data: <strong>function<\/strong> () {\n  <strong>return<\/strong> {\n    count: 0\n  }\n}<\/code><\/pre>\n\n\n\n<div style=\"height:42px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-vivid-red-color has-text-color has-large-font-size\">\u7ec4\u4ef6\u5355\u5411\u6570\u636e\u6d41<\/p>\n\n\n\n<p>\u800c\u5b9e\u9645\u5f00\u53d1\u4e2d\uff0c\u590d\u7528\u7684\u7ec4\u4ef6\u91cc\u663e\u793a\u7684\u5185\u5bb9\u5f80\u5f80\u662f\u4e0d\u540c\u7684\uff0c\u56e0\u6b64\u6211\u4eec\u9700\u8981\u4ece\u7236\u7ec4\u4ef6\u4f20\u9012\u4e0d\u540c\u5185\u5bb9\u7ed9\u5b50\u7ec4\u4ef6\u3002<\/p>\n\n\n\n<p>\u6211\u4eec\u4f7f\u7528 prop<\/p>\n\n\n\n<div style=\"height:25px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-vivid-red-color has-text-color\">\u5411prop\u4f20\u8f93\u6570\u636e\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"markup\" class=\"language-markup\">&lt;template&gt;\n  &lt;div id=\"app\"&gt;\n    <em>&lt;!-- \u6ce8\u610f\uff01title1 \u548c title2 \u662f\u7236\u7ec4\u4ef6\u7684 data \u4e2d\u5b9a\u4e49\u7684\u6570\u636e\uff0ctitle \u5219\u662f\u5b50\u7ec4\u4ef6\u4e2d\u63a5\u6536\u6570\u636e\u65f6\u7684\u53d8\u91cf\u540d --&gt;<\/em>\n    &lt;HelloVue :title=\"title1\"&gt;&lt;\/HelloVue&gt;\n    &lt;HelloVue :title=\"title2\"&gt;&lt;\/HelloVue&gt;\n  &lt;\/div&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<p> title1 \u548c title2 \u662f\u7236\u7ec4\u4ef6\u7684 data \u4e2d\u5b9a\u4e49\u7684\u6570\u636e\uff0ctitle \u5219\u662f\u5b50\u7ec4\u4ef6\u4e2d\u63a5\u6536\u6570\u636e\u65f6\u7684\u53d8\u91cf\u540d<\/p>\n\n\n\n<p>\u7531\u4e8e title1 \u548c title2 \u662f\u53d8\u91cf\uff0c\u6240\u4ee5 title \u524d\u8981\u52a0 \uff1a<\/p>\n\n\n\n<div style=\"height:26px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-vivid-red-color has-text-color\">prop\u63a5\u53d7\u6570\u636e<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\">&lt;template&gt;\n  &lt;div class=\"hello\"&gt;\n    <em>&lt;!-- \u7b2c\u4e8c\u6b65\uff1a\u5728\u9875\u9762\u4e0a\u663e\u793a title \u7684\u503c\uff0c\u5199\u6cd5\u548c\u663e\u793a data \u91cc\u5b9a\u4e49\u7684\u6570\u636e\u4e00\u6837 --&gt;<\/em>\n    &lt;h1&gt;{{ title }}&lt;\/h1&gt;\n  &lt;\/div&gt;\n&lt;\/template&gt;\n\n&lt;script&gt;\n  <strong>export<\/strong> <strong>default<\/strong> {\n    name: 'HelloVue',\n    <em>\/\/ \u7b2c\u4e00\u6b65\uff1a\u5728 prop \u5c5e\u6027\u4e2d\u63a5\u6536 title<\/em>\n    props: ['title']\n  };\n&lt;\/script&gt;<\/code><\/pre>\n\n\n\n<p>\u56e0\u4e3a\u4f20\u8fc7\u6765\u7684\u6570\u636e\u53ef\u80fd\u4e0d\u6b62\u4e00\u4e2a\uff0c\u6240\u4ee5props\u4e2d title \u662f\u4ee5\u6570\u7ec4\u7684\u5f62\u5f0f\u8868\u8fbe\u7684\u3002<\/p>\n\n\n\n<div style=\"height:14px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>\u540c\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u58f0\u660e\u6570\u636e\u7c7b\u578b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\"> props: {\n      title: String\n    }\n<\/code><\/pre>\n\n\n\n<div style=\"height:23px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>\u5f53\u4f20\u5165\u4e3a\u5bf9\u8c61\uff0c\u503c\u6709\u591a\u4e2a\u7684\u65f6\u5019\uff0c\u6211\u4eec\u4f7f\u7528\u9017\u53f7\u9694\u5f00<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\">props: {\n  title: String,\n  <em>\/\/ \u591a\u7c7b\u578b<\/em>\n  likes: [String, Number],\n  <em>\/\/ \u5e26\u6709\u9ed8\u8ba4\u503c<\/em>\n  isPublished: {\n    type: Boolean,\n    default: true\n  },\n  <em>\/\/ \u5fc5\u586b<\/em>\n  commentIds: {\n    type: Array,\n    required: true\n  },\n  author: Object,\n  callback: Function,\n  contactsPromise: Promise\n}<\/code><\/pre>\n\n\n\n<div style=\"height:35px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-vivid-red-color has-text-color\">\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5355\u5411\u6570\u636e\u6d41\u662f\u7236\u5bf9\u5b50\u7684\u5355\u5411\u6d41\u901a<\/p>\n\n\n\n<p class=\"has-vivid-red-color has-text-color\">\u7236\u7ec4\u4ef6\u6570\u636e\u53d8\u5316\u4f1a\u901a\u8fc7prop\u4f20\u9012\u5230\u5b50\u7ec4\u4ef6\uff0c\u4f46\u5b50\u7ec4\u4ef6\u4e0d\u80fd\u76f4\u63a5\u4fee\u6539\u4f20\u9012\u8fc7\u6765\u7684prop<\/p>\n\n\n\n<p>\u5982\u679c\u6211\u4eec\u9700\u8981\u4fee\u6539\u4f20\u9012\u8fc7\u6765\u7684prop<\/p>\n\n\n\n<p class=\"has-medium-font-size\">1.\u4f7f\u7528\u8ba1\u7b97\u5c5e\u6027\u8fdb\u884c\u5904\u7406<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\">props: ['initialTitle'],\ncomputed: {\n  normalizedTitle: <strong>function<\/strong> () {\n    <em>\/\/ \u5bf9\u4f20\u5165\u7684 initialTitle \u8fdb\u884c\u53bb\u7a7a\u683c\u3001\u5b57\u6bcd\u5c0f\u5199\u5316\u5904\u7406<\/em>\n    <strong>return<\/strong> this.initialTitle.trim().toLowerCase()\n  }\n}<\/code><\/pre>\n\n\n\n<p>2.\u5c06prop\u4f20\u5165\u6570\u636e\u53d8\u4e3a\u672c\u5730\u6570\u636e\u8fdb\u884c\u5904\u7406<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\">props: ['initialTitle'],\ndata: <strong>function<\/strong> () {\n  <strong>return<\/strong> {\n    <em>\/\/ \u8981\u8bfb\u53d6 prop \u91cc\u7684 initialTitle\uff0c\u8981\u5728\u524d\u9762\u52a0 \u201cthis.\u201d<\/em>\n    <em>\/\/ \u5c06\u4f20\u5165\u7684 initialTitle \u4f5c\u4e3a\u672c\u5730\u5c5e\u6027 title \u7684\u521d\u59cb\u503c<\/em>\n    title: this.initialTitle\n  }\n}<\/code><\/pre>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-vivid-red-color has-text-color has-large-font-size\">\u81ea\u5b9a\u4e49\u7ec4\u4ef6\u7ed1\u5b9a\u539f\u751f\u4e8b\u4ef6<\/p>\n\n\n\n<p>\u5f53\u6211\u4eec\u5728\u5b50\u7ec4\u4ef6\u5185\u8bbe\u7f6e\u4e86\u4e8b\u4ef6\uff08\u5982\u70b9\u51fb\u4e8b\u4ef6\uff09\u7684\u540c\u65f6\uff0c\u5728\u7236\u7ec4\u4ef6\u4e2d\u5f15\u5165\u7684\u5b50\u7ec4\u4ef6\u6807\u7b7e\u4e0a\u4e5f\u6dfb\u52a0\u4e86\u4e8b\u4ef6\uff08\u5982\u70b9\u51fb\u4e8b\u4ef6\uff09\uff0c\u5f53\u6211\u4eec\u70b9\u51fb\u8fd9\u4e2a\u6807\u7b7e\uff0c<span class=\"has-inline-color has-vivid-red-color\">\u4f1a\u53d1\u73b0\u53ea\u6709\u5b50\u7ec4\u4ef6\uff08\u81ea\u5b9a\u4e49\u7ec4\u4ef6\uff09\u7684\u4e8b\u4ef6\u88ab\u89e6\u53d1\u4e86\uff0c\u800c\u7236\u7ec4\u4ef6\uff08\u539f\u751f\u7ec4\u4ef6\uff09\u7684\u4e8b\u4ef6\u6ca1\u6709\u89e6\u53d1\u3002<\/span><\/p>\n\n\n\n<p>\u8fd9\u79cd\u60c5\u51b5\uff0c\u5982\u679c\u6211\u4eec\u9700\u8981\u7236\u7ec4\u4ef6\u4e8b\u4ef6\u4e00\u8d77\u89e6\u53d1\uff0c\u53ef\u4ee5\u6dfb\u52a0 Vue \u4fee\u9970\u7b26<\/p>\n\n\n\n<p>\u4fee\u9970\u7b26\u4f7f\u7528\u70b9\u5f00\u5934\u7684\u6307\u4ee4\u540e\u7f00\u8868\u793a\u7684 \u5982 <code>.prevent<\/code> \u548c <code>.capture<\/code><\/p>\n\n\n\n<p>\u800c\u8981\u8ba9\u7236\u7ec4\u4ef6\u5185\u5bb9\u88ab\u6267\u884c\uff0c\u6211\u4eec\u9700\u8981\u6dfb\u52a0 <code>.native<\/code> \u4fee\u9970\u7b26\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"markup\" class=\"language-markup\">&lt;Article\n  v-for=\"article in articleList\"\n  :key=\"article.title\"\n  :article=\"article\"\n  @click.native=\"print(article)\"\n&gt;&lt;\/Article&gt;<\/code><\/pre>\n\n\n\n<div style=\"height:40px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-vivid-red-color has-text-color has-large-font-size\">\u6309\u952e\u4fee\u9970\u7b26<\/p>\n\n\n\n<p>\u5f53\u6211\u4eec\u9700\u8981\u6dfb\u52a0\u6309\u952e\u70b9\u51fb\u4e8b\u4ef6\u65f6\uff0c\u9700\u8981\u6dfb\u52a0 <code>keyup<\/code> \u4e8b\u4ef6\uff0c\u6b64\u65f6\u6211\u4eec\u9700\u8981\u8bbe\u5b9a\u8fd9\u4e2a\u4e8b\u4ef6\u5bf9\u5e94\u7684\u952e\u76d8\u6309\u952e\u3002<\/p>\n\n\n\n<p>\u5982\u5bf9\u5e94\u56de\u8f66\u952e\uff08enter\u6309\u952e\uff09:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"markup\" class=\"language-markup\">&lt;button @keyup.enter=\"print(article)\"&gt;\u6309\u56de\u8f66\u952e\u6267\u884c print&lt;\/button&gt;<\/code><\/pre>\n\n\n\n<p>\u56e0\u4e3a\u56de\u8f66\u952e\u7684 ASCII\u7801\u5bf9\u5e94\u7684\u662f 13\uff0c\u6240\u4ee5\u4e5f\u53ef\u4ee5\u7528\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"markup\" class=\"language-markup\">&lt;button @keyup.13=\"print(article)\"&gt;\u6309\u56de\u8f66\u952e\u6267\u884c print&lt;\/button&gt;<\/code><\/pre>\n\n\n\n<div style=\"height:42px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-vivid-red-color has-text-color has-large-font-size\">\u81ea\u5b9a\u4e49\u4e8b\u4ef6<\/p>\n\n\n\n<p>\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u5f53\u6211\u4eec\u9700\u8981\u63d0\u4f9b \u5b50\u7ec4\u4ef6\u91cc\u7684\u70b9\u8d5e\u6309\u94ae\u6765\u6539\u53d8 \u7236\u7ec4\u4ef6\u91cc\u7684\u70b9\u8d5e\u6570\uff0c\u6b64\u65f6\u6211\u4eec\u9700\u8981\u901a\u8fc7\u5b50\u7ec4\u4ef6\u6765\u4fee\u6539\u7236\u7ec4\u4ef6\u7684\u6570\u636e\uff0c\u5728\u4e4b\u524d\u7684\u5185\u5bb9\u4e2d\u53ef\u77e5\uff0c\u6309\u4e4b\u524d\u7684\u65b9\u6cd5\u662f\u65e0\u6cd5\u5b9e\u73b0\u7684\uff0c\u6b64\u65f6\u6211\u4eec\u9700\u8981\u4f7f\u7528\u81ea\u5b9a\u4e49\u7ec4\u4ef6\u3002<\/p>\n\n\n\n<p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5728\u7236\u7ec4\u4ef6\u4e2d\u5c06\u5b50\u7ec4\u4ef6\u7ed1\u5b9a\u4e00\u4e2a\u81ea\u5b9a\u4e49\u4e8b\u4ef6 <code>v-on:upVote=\"handleLikes\"<\/code><\/p>\n\n\n\n<p>\u5176\u4e2d upVote \u662f\u81ea\u5b9a\u4e49\u4e8b\u4ef6\u7684\u540d\u79f0\uff0c\u7c7b\u6bd4\u4e8e\u70b9\u51fb\u4e8b\u4ef6\u7ed1\u5b9a <code>v-on:click<\/code> \u3002 handleLikes \u662f\u4e8b\u4ef6\u7ed1\u5b9a\u7684\u65b9\u6cd5\uff0c\u7ed3\u5408\u4e0a\u8ff0\u8981\u6c42\uff0c\u5373\u662f\u7236\u7ec4\u4ef6\u91cc\u6539\u53d8\u70b9\u8d5e\u6570\u7684\u65b9\u6cd5\u3002<\/p>\n\n\n\n<p>   <\/p>\n\n\n\n<p>\u7136\u540e\u6211\u4eec\u9700\u8981\u5728\u5b50\u7ec4\u4ef6\u5185\u8c03\u7528\u81ea\u5b9a\u4e49\u4e8b\u4ef6<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"markup\" class=\"language-markup\">&lt;button @click=\"$emit('upVote')\"&gt;\u70b9\u8d5e&lt;\/button&gt;<\/code><\/pre>\n\n\n\n<div style=\"height:12px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>\u5982\u679c\u6709\u591a\u4e2a\u4e8b\u4ef6\u53ef\u4ee5<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"markup\" class=\"language-markup\">&lt;button @click=\"childEvent\"&gt;\u70b9\u8d5e&lt;\/button&gt;\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\">methods: {\n  childEvent: <strong>function<\/strong>() {\n    <em>\/\/ \u8c03\u7528\u81ea\u5b9a\u4e49\u4e8b\u4ef6 upVote<\/em>\n    this.$emit('upVote');\n    <em>\/\/ do other things<\/em>\n  }\n}<\/code><\/pre>\n\n\n\n<div style=\"height:21px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>\u5982\u679c\u6211\u4eec\u53c2\u6570\u7684\u4f20\u9012\u5982<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\"><em>\/\/ \u5728 `methods` \u5bf9\u8c61\u4e2d\u5b9a\u4e49\u65b9\u6cd5<\/em>\nmethods: {\n  <strong>handleLikes<\/strong>(article) {\n    article.likes++\n  }\n}<\/code><\/pre>\n\n\n\n<p>\u53ef\u4ee5\u5728\u5b50\u7ec4\u4ef6\u7684 <code>$emit<\/code> \u4e2d\u5199\u5165\u591a\u4e2a\u53c2\u6570\u8868\u793a\u53c2\u6570\u4f20\u9012<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\">this.$emit('upVote', this.article);<\/code><\/pre>\n\n\n\n<div style=\"height:27px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>\u5982\u679c\u6211\u4eec\u6dfb\u52a0 <code>.sync<\/code> \u4fee\u9970\u7b26\uff0c\u53ef\u4ee5\u8868\u793a\u53cc\u5411\u7ed1\u5b9a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"markup\" class=\"language-markup\">&lt;MyCount class=\"count\" :count.sync=\"count\"&gt;&lt;\/MyCount&gt;\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"markup\" class=\"language-markup\">&lt;div class=\"my-count\"&gt;\n  &lt;button @click=\"$emit('update:count', count+1)\"&gt;\u52a0\u4e00&lt;\/button&gt;\n  {{ count }}\n&lt;\/div&gt;<\/code><\/pre>\n\n\n\n<div style=\"height:34px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-vivid-red-color has-text-color has-large-font-size\">\u7ec4\u4ef6\u51fd\u6570\u8c03\u7528<\/p>\n\n\n\n<p>\u7236\u7ec4\u4ef6\u662f\u53ef\u4ee5\u76f4\u63a5\u8bbf\u95ee\u5b50\u7ec4\u4ef6\u7684\u51fd\u6570\u7684\u3002<\/p>\n\n\n\n<p>\u9996\u5148\u6211\u4eec\u4f7f\u7528<code> ref <\/code>\u5c5e\u6027\u6dfb\u52a0\u9700\u8981\u8c03\u7528\u7684\u7ec4\u4ef6<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"markup\" class=\"language-markup\">&lt;template&gt;\n  &lt;Modal ref=\"modal\"&gt;&lt;\/Modal&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<p>\u7136\u540e\u6211\u4eec\u5c31\u53ef\u4ee5\u76f4\u63a5\u5728\u7236\u7ec4\u4ef6\u65b9\u6cd5\u4e2d\u8c03\u7528\u5b50\u7ec4\u4ef6\u51fd\u6570\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\">  methods: {\n    <strong>showModal<\/strong>() {\n      <em>\/\/ \u8c03\u7528\u5b50\u7ec4\u4ef6\u4e2d\u7684 show \u65b9\u6cd5<\/em>\n      this.$refs.modal.show();\n    }\n  }<\/code><\/pre>\n\n\n\n<div style=\"height:29px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>\u9664\u4e86\u53ef\u4ee5\u8c03\u7528\u5b50\u7ec4\u4ef6\u51fd\u6570\uff0cref\u5c5e\u6027\u4e5f\u53ef\u4ee5\u8c03\u7528\u5b50\u5143\u7d20<\/p>\n\n\n\n<p>\u5982<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"markup\" class=\"language-markup\">&lt;input ref=\"input\" type=\"text\" \/><\/code><\/pre>\n\n\n\n<p>input\u662fHTML\u539f\u751f\u7684\u8868\u5355\u5143\u7d20\uff0c\u5b83\u5b58\u5728\u7740\u81ea\u5df1\u7684 focus() \u65b9\u6cd5\u6765\u805a\u7126\uff0c\u53ef\u4ee5\u7528ref\u6765\u8c03\u7528\u8fd9\u4e2a\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"javascript\" class=\"language-javascript\"> <strong>focusInput<\/strong>() {\n      <em>\/\/ this.$refs.input \u8bbf\u95ee\u8f93\u5165\u6846\u5143\u7d20\uff0c\u5e76\u8c03\u7528 focus() \u65b9\u6cd5\u4f7f\u5176\u83b7\u53d6\u7126\u70b9<\/em>\n      this.$refs.input.focus();\n    }<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u7ec4\u4ef6\u5c31\u662f\u53ef\u590d\u7528\u7684Vue\u5b9e\u4f8b\uff0c\u5728\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u628a\u91cd\u590d\u4f7f\u7528\u7684\u529f\u80fd\u5c01\u88c5\u6210\u81ea\u5b9a\u4e49\u7ec4\u4ef6\uff0c\u4ee5\u8fbe\u5230\u4fbf\u6377\u5f00\u53d1\u7684\u76ee\u7684\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","footnotes":""},"categories":[5],"tags":[],"class_list":["post-776","post","type-post","status-publish","format-standard","hentry","category-5"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/posts\/776"}],"collection":[{"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/comments?post=776"}],"version-history":[{"count":13,"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/posts\/776\/revisions"}],"predecessor-version":[{"id":794,"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/posts\/776\/revisions\/794"}],"wp:attachment":[{"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/media?parent=776"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/categories?post=776"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/tags?post=776"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}