{"id":8219,"date":"2022-11-02T12:52:47","date_gmt":"2022-11-02T04:52:47","guid":{"rendered":"http:\/\/123.57.164.21\/?p=8219"},"modified":"2022-11-02T12:52:47","modified_gmt":"2022-11-02T04:52:47","slug":"vue%e7%88%b6%e5%ad%90%e7%bb%84%e4%bb%b6%e9%80%9a%e4%bf%a1%ef%bc%88props%ef%bc%8cemit%ef%bc%89","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=8219","title":{"rendered":"Vue\u7236\u5b50\u7ec4\u4ef6\u901a\u4fe1\uff08props\uff0c$emit\uff09"},"content":{"rendered":"\n<p><strong>\u901a\u8fc7props\u5b9e\u73b0\u7236\u7ec4\u4ef6\u5411\u5b50\u7ec4\u4ef6\u4f20\u9012\u6570\u636e\uff1a<\/strong><\/p>\n\n\n\n<p>App\u7ec4\u4ef6\u4e2d\u5305\u542blist\u6570\u636e\uff0c\u8981\u628aApp\u4e2d\u7684list\u6570\u636e\u4f20\u9012\u7ed9List\u5b50\u7ec4\u4ef6\uff0c\u5e76\u7531\u5b50\u7ec4\u4ef6\u5c55\u793a\u5230\u9875\u9762\u4e2d\u3002<\/p>\n\n\n\n<p>\u7236\u7ec4\u4ef6APP:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;template>\n    &lt;div>\n        &lt;MyList :list=\"list\"\/>    \/\/Mylist\u7ec4\u4ef6\u7ed1\u5b9adata\u4e2d\u7684list\n    &lt;\/div>\n&lt;\/template>\n\n&lt;script>\nimport MyList from '.\/components\/List.vue'   \n\nexport default {\n    components: { MyList},\n    data() {\n\treturn {\n\t    list: [\n\t        {\n\t\t    id: 1,\n\t\t    title: 'a1'\n\t\t},\n               {\n\t\t    id: 2,\n\t\t    title: 'a2'\n\t\t}\n\t    ]\n\t}\n    },\t\t\n}\n&lt;\/script><\/pre>\n\n\n\n<p>\u5b50\u7ec4\u4ef6MyList\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;template>\n  &lt;div>\n    &lt;ul>\n      \/\/\u904d\u5386list\u5e76\u5c55\u793a\n      &lt;li v-for=\"item in list\" :key=\"item.id\">\n        {{ item.title }}\n      &lt;\/li>\n    &lt;\/ul>\n  &lt;\/div>\n&lt;\/template>\n\n&lt;script>\nexport default {\n  \/\/\u901a\u8fc7props\u63a5\u6536App\u4e2d\u7684list\u6570\u636e\uff0c\u6307\u5b9a\u7c7b\u578b\u4e3a\u6570\u7ec4\n  props:{\n    list: Array\n  }\n}\n&lt;\/script><\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/11\/image.png\" alt=\"\" class=\"wp-image-8220\" width=\"445\" height=\"459\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/image.png 744w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/image-291x300.png 291w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/image-230x237.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/image-350x361.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/image-480x495.png 480w\" sizes=\"(max-width: 445px) 100vw, 445px\" \/><\/figure><\/div>\n\n\n\n<p><strong>\u901a\u8fc7$emit\u5b9e\u73b0\u5b50\u7ec4\u4ef6\u5411\u7236\u7ec4\u4ef6\u4f20\u9012\u6570\u636e\uff1a<\/strong><\/p>\n\n\n\n<p>\u5728MyInput\u5b50\u7ec4\u4ef6\u4e2d\uff0c\u901a\u8fc7\u5728\u8f93\u5165\u6846\u8f93\u5165\u6570\u636e\u5e76\u70b9\u51fb\u6dfb\u52a0\u6309\u94ae\u628a\u8f93\u5165\u7684\u6570\u636e\u4fdd\u5b58\u5230App\u7684list\u4e2d\u3002<\/p>\n\n\n\n<p>\u5b50\u7ec4\u4ef6MyInput\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;template>\n  &lt;div class=\"input\">\n    &lt;input type=\"text\" v-model=\"title\">    \/\/\u7ed1\u5b9ainput\u6846\u4e2d\u7684title\u6570\u636e\n    &lt;button @click=\"add\">\u6dfb\u52a0&lt;\/button>    \/\/\u6dfb\u52a0\u6309\u94ae\u70b9\u51fb\u4e8b\u4ef6\u56de\u8c03add\n  &lt;\/div>\n&lt;\/template>\n\n&lt;script>\nexport default {\n  data() {\n    return {\n      title: ''\n    }\n  },\n  methods: {\n    \/\/\u901a\u8fc7add\u65b9\u6cd5\u4e2d\u7684$emit\u628atitle\u53d1\u9001\u51fa\u53bb\n    add() {\n      this.$emit('add', this.title)\n    }\n  }\n}\n&lt;\/script><\/pre>\n\n\n\n<p>App\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;template>\n    &lt;div>\n        &lt;MyInput @add=\"add\"\/>    \/\/\u76d1\u542cMyInput\u7684add\n    &lt;\/div>\n&lt;\/template>\n\n&lt;script>\nimport MyInput from '.\/components\/Input.vue'  \n\nexport default {\n    components: { MyInput},\n    data() {\n\treturn {\n\t    list: [\n\t        {\n\t\t    id: 1,\n\t\t    title: 'a1'\n\t\t},\n               {\n\t\t    id: 2,\n\t\t    title: 'a2'\n\t\t}\n\t    ]\n\t}\n    },\t\n    methods: {\n        \/\/\u63a5\u6536\u5230add\u4e2d\u7684title\u540e\u628atitle\u6dfb\u52a0\u5230list\u4e2d\n\tadd(title) {\n\t    this.list.push({\n\t        id: Math.random(),    \/\/\u4f7f\u7528\u968f\u673a\u6570\u4f5c\u4e3aid\n\t\ttitle\n\t    })\n        }\n    },\t\n}\n&lt;\/script><\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2022\/11\/image-1.png\" alt=\"\" class=\"wp-image-8221\" width=\"497\" height=\"354\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/image-1.png 924w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/image-1-300x214.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/image-1-768x547.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/image-1-830x591.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/image-1-230x164.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/image-1-350x249.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2022\/11\/image-1-480x342.png 480w\" sizes=\"(max-width: 497px) 100vw, 497px\" \/><\/figure><\/div>\n\n\n\n<p>MyInput\u7ec4\u4ef6\u628a\u8f93\u5165\u6846\u7684\u5185\u5bb9\u4f20\u9012\u7ed9App\u4e4b\u540e\uff0cApp\u4e2dlist\u6570\u636e\u589e\u52a0\uff0c\u81ea\u7136\u4e5f\u4f1a\u4f20\u9012\u7ed9MyList\u7ec4\u4ef6\u5e76\u5c55\u793a\u5230\u9875\u9762\u4e0a\u3002<\/p>\n\n\n\n<p>\u5b8c\u6574App\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;template>\n    &lt;div>\n        &lt;MyInput @add=\"add\"\/>    \/\/\u76d1\u542cMyInput\u7684add\n        &lt;MyList :list=\"list\"\/>\n    &lt;\/div>\n&lt;\/template>\n\n&lt;script>\nimport MyInput from '.\/components\/Input.vue'  \nimport MyList from '.\/components\/List.vue'\n\nexport default {\n    components: { MyInput\uff0c MyList},\n    data() {\n\treturn {\n\t    list: [\n\t        {\n\t\t    id: 1,\n\t\t    title: 'a1'\n\t\t},\n               {\n\t\t    id: 2,\n\t\t    title: 'a2'\n\t\t}\n\t    ]\n\t}\n    },\t\n    methods: {\n        \/\/\u63a5\u6536\u5230add\u4e2d\u7684title\u540e\u628atitle\u6dfb\u52a0\u5230list\u4e2d\n\tadd(title) {\n\t    this.list.push({\n\t        id: Math.random(),    \/\/\u4f7f\u7528\u968f\u673a\u6570\u4f5c\u4e3aid\n\t\ttitle\n\t    })\n        }\n    },\t\n}\n&lt;\/script><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u901a\u8fc7props\u5b9e\u73b0\u7236\u7ec4\u4ef6\u5411\u5b50\u7ec4\u4ef6\u4f20\u9012\u6570\u636e\uff1a App\u7ec4\u4ef6\u4e2d\u5305\u542blist\u6570\u636e\uff0c\u8981\u628aApp\u4e2d\u7684list\u6570\u636e\u4f20\u9012\u7ed9Li [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/8219"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8219"}],"version-history":[{"count":1,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/8219\/revisions"}],"predecessor-version":[{"id":8222,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/8219\/revisions\/8222"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8219"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}