{"id":109,"date":"2025-11-04T10:40:18","date_gmt":"2025-11-04T02:40:18","guid":{"rendered":"https:\/\/gd.patchouli-go.cn\/?p=109"},"modified":"2025-11-04T10:42:02","modified_gmt":"2025-11-04T02:42:02","slug":"%e8%bd%ac%e8%bd%bd%ef%bc%9avue%e9%98%b2%e6%8a%96%e4%b8%8e%e8%8a%82%e6%b5%81%e7%9a%84%e6%9c%80%e4%bd%b3%e8%a7%a3%e5%86%b3%e6%96%b9%e6%a1%88-%e5%87%bd%e6%95%b0%e5%bc%8f%e7%bb%84","status":"publish","type":"post","link":"https:\/\/gd.patchouli-go.cn\/?p=109","title":{"rendered":"\u8f6c\u8f7d\uff1aVUE\u9632\u6296\u4e0e\u8282\u6d41\u7684\u6700\u4f73\u89e3\u51b3\u65b9\u6848\u2014\u2014\u51fd\u6570\u5f0f\u7ec4\u4ef6"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u6765\u6e90\uff1a<a href=\"https:\/\/www.ucloud.cn\/yun\/6841.html\">https:\/\/www.ucloud.cn\/yun\/6841.html<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6458\u8981\uff1a\u6848\u4f8b\u6301\u7eed\u89e6\u53d1\u4e8b\u4ef6\u65f6\uff0c\u5e76\u4e0d\u7acb\u5373\u6267\u884c\u51fd\u6570\uff0c\u5f53\u6beb\u79d2\u5185\u6ca1\u6709\u89e6\u53d1\u4e8b\u4ef6\u65f6\uff0c\u624d\u4f1a\u5ef6\u65f6\u89e6\u53d1\u4e00\u6b21\u51fd\u6570\u3002\u4e5f\u4ee5\u51fd\u6570\u5f62\u5f0f\u66b4\u9732\u666e\u901a\u63d2\u69fd\u3002\u8fd9\u6837\u7684\u573a\u666f\u7ec4\u4ef6\u7528\u51fd\u6570\u5f0f\u7ec4\u4ef6\u662f\u975e\u5e38\u65b9\u4fbf\u7684\u3002\u76f8\u5173\u9605\u8bfb\u51fd\u6570\u5f0f\u7ec4\u4ef6\u81ea\u5b9a\u4e49\u6307\u4ee4<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u524d\u8a00<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6709echarts\u4f7f\u7528\u7ecf\u9a8c\u7684\u540c\u5b66\u53ef\u80fd\u9047\u5230\u8fc7\u8fd9\u6837\u7684\u573a\u666f\uff0c\u5728window.onresize\u4e8b\u4ef6\u56de\u8c03\u91cc\u89e6\u53d1echartsBox.resize()\u65b9\u6cd5\u6765\u8fbe\u5230\u91cd\u7ed8\u7684\u76ee\u7684\uff0cresize\u4e8b\u4ef6\u662f\u8fde\u7eed\u89e6\u53d1\u7684\u8fd9\u610f\u5473\u7740echarts\u5b9e\u4f8b\u4f1a\u8fde\u7eed\u7684\u91cd\u7ed8\u8fd9\u662f\u975e\u5e38\u8017\u6027\u80fd\u7684\u3002\u8fd8\u6709\u4e00\u4e2a\u5e38\u89c1\u7684\u573a\u666f\u5728input\u6807\u7b7e\u7684input\u4e8b\u4ef6\u91cc\u8bf7\u6c42\u540e\u7aef\u63a5\u53e3\uff0cinput\u4e8b\u4ef6\u4e5f\u662f\u8fde\u7eed\u89e6\u53d1\u7684\uff0c\u5047\u8bbe\u6211\u8f93\u5165\u4e86\u201c12\u201d\u5c31\u4f1a\u8bf7\u6c42\u4e24\u6b21\u63a5\u53e3\u53c2\u6570\u5206\u522b\u662f\u201c1\u201d\u548c\u201c12\u201d\uff0c\u6bd4\u6d6a\u8d39\u7f51\u7edc\u8d44\u6e90\u66f4\u8981\u547d\u7684\u662f\u5982\u679c\u53c2\u6570\u4e3a\u201c1\u201d\u7684\u8bf7\u6c42\u8fd4\u56de\u6570\u636e\u7684\u65f6\u95f4\u665a\u4e8e\u53c2\u6570\u4e3a\u201c12\u201d\u7684\u63a5\u53e3\uff0c\u90a3\u4e48\u6211\u4eec\u5f97\u5230\u7684\u6570\u636e\u662f\u548c\u671f\u671b\u4e0d\u7b26\u7684\u3002\u5f53\u7136\u57fa\u4e8eaxios\u53ef\u4ee5\u505a\u5f88\u591a\u5c01\u88c5\u53ef\u4ee5\u53d6\u6d88\u4e0a\u4e00\u4e2a\u8bf7\u6c42\u6216\u8005\u901a\u8fc7\u62e6\u622a\u505a\u5904\u7406\uff0c\u4f46\u8fd8\u662f\u4ece\u9632\u6296\u5165\u624b\u6bd4\u8f83\u7b80\u5355\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u9632\u6296\u548c\u8282\u6d41\u5230\u5e95\u662f\u5565<\/strong><strong>\u51fd\u6570\u9632\u6296\uff08debounce\uff09<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u89e3\u91ca\uff1a\u5f53\u6301\u7eed\u89e6\u53d1\u67d0\u4e8b\u4ef6\u65f6\uff0c\u4e00\u5b9a\u65f6\u95f4\u95f4\u9694\u5185\u6ca1\u6709\u518d\u89e6\u53d1\u4e8b\u4ef6\u65f6\uff0c\u4e8b\u4ef6\u5904\u7406\u51fd\u6570\u624d\u4f1a\u6267\u884c\u4e00\u6b21\uff0c\u5982\u679c\u8bbe\u5b9a\u7684\u65f6\u95f4\u95f4\u9694\u5230\u6765\u4e4b\u524d\uff0c\u53c8\u4e00\u6b21\u89e6\u53d1\u4e86\u4e8b\u4ef6\uff0c\u5c31\u91cd\u65b0\u5f00\u59cb\u5ef6\u65f6\u3002<br>\u6848\u4f8b\uff1a\u6301\u7eed\u89e6\u53d1scroll\u4e8b\u4ef6\u65f6\uff0c\u5e76\u4e0d\u7acb\u5373\u6267\u884chandle\u51fd\u6570\uff0c\u5f531000\u6beb\u79d2\u5185\u6ca1\u6709\u89e6\u53d1scroll\u4e8b\u4ef6\u65f6\uff0c\u624d\u4f1a\u5ef6\u65f6\u89e6\u53d1\u4e00\u6b21handle\u51fd\u6570\u3002<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-javascript\">function debounce(fn, wait) {\n  let timeout = null\n  return function() {\n    if(timeout !== null) clearTimeout(timeout)     \n    timeout = setTimeout(fn, wait);\n  }\n}\nfunction handle() {   \n  console.log(Math.random())\n}\nwindow.addEventListener(&quot;scroll&quot;, debounce(handle, 1000))\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>addEventListener\u7684\u7b2c\u4e8c\u4e2a\u53c2\u6570\u5b9e\u9645\u4e0a\u662fdebounce\u51fd\u6570\u91ccreturn\u56de\u7684\u65b9\u6cd5\uff0clet timeout = null&nbsp;\u8fd9\u884c\u4ee3\u7801\u53ea\u5728addEventListener\u7684\u65f6\u5019\u6267\u884c\u4e86\u4e00\u6b21 \u89e6\u53d1\u4e8b\u4ef6\u7684\u65f6\u5019\u4e0d\u4f1a\u6267\u884c\uff0c\u90a3\u4e48\u6bcf\u6b21\u89e6\u53d1scroll\u4e8b\u4ef6\u7684\u65f6\u5019\u90fd\u4f1a\u6e05\u9664\u4e0a\u6b21\u7684\u5ef6\u65f6\u5668\u540c\u65f6\u8bb0\u5f55\u4e00\u4e2a\u65b0\u7684\u5ef6\u65f6\u5668\uff0c\u5f53scroll\u4e8b\u4ef6\u505c\u6b62\u89e6\u53d1\u540e\u6700\u540e\u4e00\u6b21\u8bb0\u5f55\u7684\u5ef6\u65f6\u5668\u4e0d\u4f1a\u88ab\u6e05\u9664\u53ef\u4ee5\u5ef6\u65f6\u6267\u884c\uff0c\u8fd9\u662fdebounce\u51fd\u6570\u7684\u539f\u7406<\/strong><strong>\u51fd\u6570\u8282\u6d41\uff08throttle\uff09<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u89e3\u91ca\uff1a\u5f53\u6301\u7eed\u89e6\u53d1\u4e8b\u4ef6\u65f6\uff0c\u6709\u89c4\u5f8b\u7684\u6bcf\u9694\u4e00\u4e2a\u65f6\u95f4\u95f4\u9694\u6267\u884c\u4e00\u6b21\u4e8b\u4ef6\u5904\u7406\u51fd\u6570\u3002<br>\u6848\u4f8b\uff1a\u6301\u7eed\u89e6\u53d1scroll\u4e8b\u4ef6\u65f6\uff0c\u5e76\u4e0d\u7acb\u5373\u6267\u884chandle\u51fd\u6570\uff0c\u6bcf\u96941000\u6beb\u79d2\u624d\u4f1a\u6267\u884c\u4e00\u6b21handle\u51fd\u6570\u3002<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-javascript\">function throttle(fn, delay) { \n  var prev = Date.now()         \n  return function() {               \n    var now = Date.now()               \n    if (now - prev &gt; delay) {                   \n      fn()                \n      prev = Date.now()             \n    }         \n  }       \n}       \nfunction handle() {           \n  console.log(Math.random())      \n}\nwindow.addEventListener(&quot;scroll&quot;, throttle(handle, 1000))\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u539f\u7406\u548c\u9632\u6296\u7c7b\u4f3c\uff0c\u6bcf\u6b21\u6267\u884cfn\u51fd\u6570\u90fd\u4f1a\u66f4\u65b0prev\u7528\u6765\u8bb0\u5f55\u672c\u6b21\u6267\u884c\u7684\u65f6\u95f4\uff0c\u4e0b\u4e00\u6b21\u4e8b\u4ef6\u89e6\u53d1\u65f6\u5224\u65ad\u65f6\u95f4\u95f4\u9694\u662f\u5426\u5230\u8fbe\u9884\u5148\u7684\u8bbe\u5b9a\uff0c\u91cd\u590d\u4e0a\u8ff0\u64cd\u4f5c\u3002<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9632\u6296\u548c\u8282\u6d41\u90fd\u53ef\u4ee5\u7528\u4e8e mousemove\u3001scroll\u3001resize\u3001input\u7b49\u4e8b\u4ef6\uff0c\u4ed6\u4eec\u7684\u533a\u522b\u5728\u4e8e\u9632\u6296\u53ea\u4f1a\u5728\u8fde\u7eed\u7684\u4e8b\u4ef6\u5468\u671f\u7ed3\u675f\u65f6\u6267\u884c\u4e00\u6b21\uff0c\u800c\u8282\u6d41\u4f1a\u5728\u4e8b\u4ef6\u5468\u671f\u5185\u6309\u95f4\u9694\u65f6\u95f4\u6709\u89c4\u5f8b\u7684\u6267\u884c\u591a\u6b21\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5728vue\u4e2d\u7684\u5b9e\u8df5<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728vue\u4e2d\u5b9e\u73b0\u9632\u6296\u65e0\u975e\u4e0b\u9762\u8fd9\u4e24\u79cd\u65b9\u6cd5<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5c01\u88c5utils\u5de5\u5177<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5c01\u88c5\u7ec4\u4ef6<strong>\u5c01\u88c5utils\u5de5\u5177<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u628a\u4e0a\u9762\u7684\u6848\u4f8b\u6539\u9020\u4e00\u4e0b\u5c31\u80fd\u5c01\u88c5\u4e00\u4e2a\u7b80\u5355\u7684utils\u5de5\u5177<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-javascript\">utils.js\nlet timeout = null\nfunction debounce(fn, wait) {\n  if(timeout !== null) clearTimeout(timeout)\n  timeout = setTimeout(fn, wait)\n}\nexport default debounce\n\napp.js\ntype=&quot;text&quot; @input=&quot;debounceInput($event)&quot;&gt;\n\nimport debounce from &quot;.\/utils&quot;\nexport default {\n  methods: {\n    debounceInput(E){\n      debounce(() =&gt; {\n        console.log(E.target.value)\n      }, 1000)\n    }\n  }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5c01\u88c5\u7ec4\u4ef6<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u81f3\u4e8e\u7ec4\u4ef6\u7684\u5c01\u88c5\u6211\u4eec\u8981\u7528\u5230<strong>$listeners\u3001$attrs<\/strong>\u8fd9\u4e24\u4e2a\u5c5e\u6027\uff0c\u4ed6\u4fe9\u90fd\u662fvue2.4\u65b0\u589e\u7684\u5185\u5bb9\uff0c\u5b98\u7f51\u7684\u4ecb\u7ecd\u6bd4\u8f83\u6666\u6da9\uff0c\u6211\u4eec\u6765\u770b\u4ed6\u4fe9\u5230\u5e95\u662f\u5e72\u5565\u7684\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>$listeners:<\/strong>&nbsp;\u7236\u7ec4\u4ef6\u5728\u7ed1\u5b9a\u5b50\u7ec4\u4ef6\u7684\u65f6\u5019\u4f1a\u5728\u5b50\u7ec4\u4ef6\u4e0a\u7ed1\u5b9a\u5f88\u591a\u5c5e\u6027\uff0c\u7136\u540e\u5728\u5b50\u7ec4\u4ef6\u91cc\u901a\u8fc7props\u6ce8\u518c\u4f7f\u7528\uff0c\u90a3\u4e48\u6ca1\u6709\u88abprops\u6ce8\u518c\u7684\u5c31\u4f1a\u653e\u5728<strong>$listeners<\/strong>\u91cc\uff0c\u5f53\u7136\u4e0d\u5305\u62ecclass\u548cstyle\uff0c\u5e76\u4e14\u53ef\u4ee5\u901a\u8fc7&nbsp;<strong>v-bind=&#8221;$attrs&#8221;<\/strong>&nbsp;\u4f20\u5165\u5b50\u7ec4\u4ef6\u7684\u5185\u90e8\u7ec4\u4ef6\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>$listeners:<\/strong>&nbsp;\u7236\u7ec4\u4ef6\u5728\u5b50\u7ec4\u4ef6\u4e0a\u7ed1\u5b9a\u7684\u4e0d\u542b.native\u4fee\u9970\u5668\u7684\u4e8b\u4ef6\u4f1a\u653e\u5728<strong>$listeners\u91cc<\/strong>\uff0c\u5b83\u53ef\u4ee5\u901a\u8fc7&nbsp;<strong>v-on=&#8221;$listeners&#8221;<\/strong>&nbsp;\u4f20\u5165\u5185\u90e8\u7ec4\u4ef6\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7b80\u5355\u6765\u8bf4<strong>$listeners\u3001$attrs<\/strong>\u4ed6\u4fe9\u662f\u505a\u5c5e\u6027\u548c\u4e8b\u4ef6\u7684\u627f\u63a5\uff0c\u8fd9\u5728\u5bf9\u7ec4\u4ef6\u505a\u4e8c\u6b21\u5c01\u88c5\u7684\u65f6\u5019\u975e\u5e38\u6709\u7528\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6211\u4eec\u4ee5element-ui\u7684el-input\u7ec4\u4ef6\u4e3a\u4f8b\u5c01\u88c5\u4e00\u4e2a\u5e26\u9632\u6296\u7684debounce-input\u7ec4\u4ef6<\/p>\n\n\n\n<pre id=\"pre4\" class=\"wp-block-code\"><code>debounce-input.vue\n\n\n\napp.vue\n\n\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u9762\u7ec4\u4ef6\u7684\u5c01\u88c5\u7528\u4e86$attrs\uff0c\u867d\u7136\u4e0d\u9700\u8981\u5f00\u53d1\u8005\u5173\u6ce8\u5c5e\u6027\u7684\u4f20\u9012\uff0c\u4f46\u662f\u5728\u4f7f\u7528\u4e0a\u8fd8\u662f\u4e0d\u65b9\u4fbf\u7684\uff0c\u56e0\u4e3a\u628ael-input\u5c01\u88c5\u5728\u4e86\u5185\u90e8\u8fd9\u6837\u5bf9\u6837\u5f0f\u7684\u9650\u5b9a\u4e5f\u6bd4\u8f83\u5c40\u9650\u3002\u6709\u63a5\u89e6\u8fc7react\u9ad8\u9636\u7ec4\u4ef6\u7684\u540c\u5b66\u53ef\u80fd\u6709\u4e86\u89e3\uff0creact\u9ad8\u9636\u7ec4\u4ef6\u672c\u8d28\u4e0a\u662f\u4e00\u4e2a\u51fd\u6570\u901a\u8fc7\u5305\u88f9\u88ab\u4f20\u5165\u7684React\u7ec4\u4ef6\uff0c\u7ecf\u8fc7\u4e00\u7cfb\u5217\u5904\u7406\uff0c\u6700\u7ec8\u8fd4\u56de\u4e00\u4e2a\u76f8\u5bf9\u589e\u5f3a\u7684React\u7ec4\u4ef6\u3002\u90a3\u4e48\u5728vue\u4e2d\u53ef\u4ee5\u501f\u9274\u8fd9\u79cd\u601d\u8def\u5417\uff0c\u6211\u4eec\u6765\u4e86\u89e3\u4e00\u4e0bvue\u7684\u51fd\u6570\u5f0f\u7ec4\u4ef6\u3002<strong>\u5173\u4e8evue\u51fd\u6570\u5f0f\u7ec4\u4ef6<\/strong><strong>\u4ec0\u4e48\u662f\u51fd\u6570\u5f0f\u7ec4\u4ef6\uff1f<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u51fd\u6570\u5f0f\u7ec4\u4ef6\u662f\u6307\u7528\u4e00\u4e2aFunction\u6765\u6e32\u67d3\u4e00\u4e2avue\u7ec4\u4ef6\uff0c\u8fd9\u4e2a\u7ec4\u4ef6\u53ea\u63a5\u53d7\u4e00\u4e9b prop\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u8fd9\u7c7b\u7ec4\u4ef6\u6807\u8bb0\u4e3a functional\uff0c\u8fd9\u610f\u5473\u7740\u5b83\u65e0\u72b6\u6001 (\u6ca1\u6709\u54cd\u5e94\u5f0f\u6570\u636e)\uff0c\u4e5f\u6ca1\u6709\u5b9e\u4f8b (\u6ca1\u6709this\u4e0a\u4e0b\u6587)\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e00\u4e2a\u51fd\u6570\u5f0f\u7ec4\u4ef6\u5927\u6982\u5411\u4e0b\u9762\u8fd9\u6837\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-javascript\">export default () =&gt; {\n  functional: true, \n  props: { \n    \/\/ Props \u662f\u53ef\u9009\u7684\n  },\n  \/\/ \u4e3a\u4e86\u5f25\u8865\u7f3a\u5c11\u7684\u5b9e\u4f8b, \u63d0\u4f9b\u7b2c\u4e8c\u4e2a\u53c2\u6570\u4f5c\u4e3a\u4e0a\u4e0b\u6587\n  render: function (createElement, context) {\n    return vNode\n  }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">\u6ce8\u610f\uff1a\u5728 2.3.0 \u4e4b\u524d\u7684\u7248\u672c\u4e2d\uff0c\u5982\u679c\u4e00\u4e2a\u51fd\u6570\u5f0f\u7ec4\u4ef6\u60f3\u8981\u63a5\u6536 prop\uff0c\u5219 props \u9009\u9879\u662f\u5fc5\u987b\u7684\u3002\u5728 2.3.0 \u6216\u4ee5\u4e0a\u7684\u7248\u672c\u4e2d\uff0c\u4f60\u53ef\u4ee5\u7701\u7565 props \u9009\u9879\uff0c\u6240\u6709\u7ec4\u4ef6\u4e0a\u7684\u7279\u6027\u90fd\u4f1a\u88ab\u81ea\u52a8\u9690\u5f0f\u89e3\u6790\u4e3a prop\u3002\u4f46\u662f\u4f60\u4e00\u65e6\u6ce8\u518c\u4e86 prop \u90a3\u4e48\u53ea\u6709\u88ab\u6ce8\u518c\u7684 prop \u4f1a\u51fa\u73b0\u5728 context.prop \u91cc\u3002\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">render\u51fd\u6570\u7684\u7b2c\u4e8c\u4e2a\u53c2\u6570context\u7528\u6765\u4ee3\u66ff\u4e0a\u4e0b\u6587this\u4ed6\u662f\u4e00\u4e2a\u5305\u542b\u5982\u4e0b\u5b57\u6bb5\u7684\u5bf9\u8c61\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">props\uff1a\u63d0\u4f9b\u6240\u6709 prop \u7684\u5bf9\u8c61<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">children: VNode \u5b50\u8282\u70b9\u7684\u6570\u7ec4<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">slots: \u4e00\u4e2a\u51fd\u6570\uff0c\u8fd4\u56de\u4e86\u5305\u542b\u6240\u6709\u63d2\u69fd\u7684\u5bf9\u8c61<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">scopedSlots: (2.6.0+) \u4e00\u4e2a\u66b4\u9732\u4f20\u5165\u7684\u4f5c\u7528\u57df\u63d2\u69fd\u7684\u5bf9\u8c61\u3002\u4e5f\u4ee5\u51fd\u6570\u5f62\u5f0f\u66b4\u9732\u666e\u901a\u63d2\u69fd\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">data\uff1a\u4f20\u9012\u7ed9\u7ec4\u4ef6\u7684\u6574\u4e2a\u6570\u636e\u5bf9\u8c61\uff0c\u4f5c\u4e3a createElement \u7684\u7b2c\u4e8c\u4e2a\u53c2\u6570\u4f20\u5165\u7ec4\u4ef6<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">parent\uff1a\u5bf9\u7236\u7ec4\u4ef6\u7684\u5f15\u7528<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">listeners: (2.3.0+) \u4e00\u4e2a\u5305\u542b\u4e86\u6240\u6709\u7236\u7ec4\u4ef6\u4e3a\u5f53\u524d\u7ec4\u4ef6\u6ce8\u518c\u7684\u4e8b\u4ef6\u76d1\u542c\u5668\u7684\u5bf9\u8c61\u3002\u8fd9\u662f data.on \u7684\u4e00\u4e2a\u522b\u540d\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">injections: (2.3.0+) \u5982\u679c\u4f7f\u7528\u4e86 inject \u9009\u9879\uff0c\u5219\u8be5\u5bf9\u8c61\u5305\u542b\u4e86\u5e94\u5f53\u88ab\u6ce8\u5165\u7684\u5c5e\u6027\u3002<strong>vm.$slots API \u91cc\u9762\u662f\u4ec0\u4e48<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">slots\u7528\u6765\u8bbf\u95ee\u88ab\u63d2\u69fd\u5206\u53d1\u7684\u5185\u5bb9\u3002\u6bcf\u4e2a\u5177\u540d\u63d2\u69fd \u6709\u5176\u76f8\u5e94\u7684\u5c5e\u6027 (\u4f8b\u5982\uff1av-slot:foo \u4e2d\u7684\u5185\u5bb9\u5c06\u4f1a\u5728 vm.$slots.foo \u4e2d\u88ab\u627e\u5230)\u3002default \u5c5e\u6027\u5305\u62ec\u4e86\u6240\u6709\u6ca1\u6709\u88ab\u5305\u542b\u5728\u5177\u540d\u63d2\u69fd\u4e2d\u7684\u8282\u70b9\uff0c\u6216 v-slot:default \u7684\u5185\u5bb9\u3002<strong>slots() \u548c children \u5bf9\u6bd4<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f60\u53ef\u80fd\u60f3\u77e5\u9053\u4e3a\u4ec0\u4e48\u540c\u65f6\u9700\u8981 slots() \u548c children\u3002slots().default \u4e0d\u662f\u548c children \u7c7b\u4f3c\u7684\u5417\uff1f\u5728\u4e00\u4e9b\u573a\u666f\u4e2d\uff0c\u662f\u8fd9\u6837\u2014\u2014\u4f46\u5982\u679c\u662f\u5982\u4e0b\u7684\u5e26\u6709\u5b50\u8282\u70b9\u7684\u51fd\u6570\u5f0f\u7ec4\u4ef6\u5462\uff1f<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">  \n    first\n  \n  second\n\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5bf9\u4e8e\u8fd9\u4e2a\u7ec4\u4ef6\uff0cchildren \u4f1a\u7ed9\u4f60\u4e24\u4e2a\u6bb5\u843d\u6807\u7b7e\uff0c\u800c slots().default \u53ea\u4f1a\u4f20\u9012\u7b2c\u4e8c\u4e2a\u533f\u540d\u6bb5\u843d\u6807\u7b7e\uff0cslots().foo \u4f1a\u4f20\u9012\u7b2c\u4e00\u4e2a\u5177\u540d\u6bb5\u843d\u6807\u7b7e\u3002\u540c\u65f6\u62e5\u6709 children \u548c slots()\uff0c\u56e0\u6b64\u4f60\u53ef\u4ee5\u9009\u62e9\u8ba9\u7ec4\u4ef6\u611f\u77e5\u67d0\u4e2a\u63d2\u69fd\u673a\u5236\uff0c\u8fd8\u662f\u7b80\u5355\u5730\u901a\u8fc7\u4f20\u9012 children\uff0c\u79fb\u4ea4\u7ed9\u5176\u5b83\u7ec4\u4ef6\u53bb\u5904\u7406\u3002<strong>\u4e00\u4e2a\u51fd\u6570\u5f0f\u7ec4\u4ef6\u7684\u4f7f\u7528\u573a\u666f<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5047\u8bbe\u6709\u4e00\u4e2aa\u7ec4\u4ef6\uff0c\u5f15\u5165\u4e86 a1,a2,a3 \u4e09\u4e2a\u7ec4\u4ef6\uff0ca\u7ec4\u4ef6\u7684\u7236\u7ec4\u4ef6\u7ed9a\u7ec4\u4ef6\u4f20\u5165\u4e86\u4e00\u4e2atype\u5c5e\u6027\u6839\u636etype\u7684\u503ca\u7ec4\u4ef6\u6765\u51b3\u5b9a\u663e\u793a a1,a2,a3 \u4e2d\u7684\u90a3\u4e2a\u7ec4\u4ef6\u3002\u8fd9\u6837\u7684\u573a\u666fa\u7ec4\u4ef6\u7528\u51fd\u6570\u5f0f\u7ec4\u4ef6\u662f\u975e\u5e38\u65b9\u4fbf\u7684\u3002\u90a3\u4e48\u4e3a\u4ec0\u4e48\u8981\u7528\u51fd\u6570\u5f0f\u7ec4\u4ef6\u5462\uff1f\u4e00\u53e5\u8bdd\uff1a\u6e32\u67d3\u5f00\u9500\u4f4e\uff0c\u56e0\u4e3a\u51fd\u6570\u5f0f\u7ec4\u4ef6\u53ea\u662f\u51fd\u6570\u3002<strong>\u7528\u51fd\u6570\u5f0f\u7ec4\u4ef6\u7684\u65b9\u5f0f\u6765\u5b9e\u73b0\u9632\u6296<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u56e0\u4e3a\u4e1a\u52a1\u5173\u7cfb\u8be5\u9632\u6296\u7ec4\u4ef6\u7684\u5c01\u88c5\u540c\u65f6\u652f\u6301 input\u3001button\u3001el-input\u3001el-button \u7684\u4f7f\u7528\uff0c\u5982\u679c\u662finput\u7c7b\u7ec4\u4ef6\u5bf9input\u4e8b\u4ef6\u505a\u9632\u6296\u5904\u7406\uff0c\u5982\u679c\u662fbutton\u7c7b\u7ec4\u4ef6\u5bf9click\u4e8b\u4ef6\u505a\u9632\u6296\u5904\u7406\u3002<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-javascript\">const debounce = (fun, delay = 500, before) =&gt; {\n  let timer = null\n  return (params) =&gt; {\n    timer &amp;&amp; window.clearTimeout(timer)\n    before &amp;&amp; before(params)\n    timer = window.setTimeout(() =&gt; {\n       \/\/ click\u4e8b\u4ef6fun\u662fFunction  input\u4e8b\u4ef6fun\u662fArray\n      if (!Array.isArray(fun)) {\n        fun = [fun]\n      }\n      for (let i in fun) {\n        fun[i](params)\n      }\n      timer = null\n    }, parseInt(delay))\n  }\n}\nexport default {\n  name: &quot;Debounce&quot;,\n  functional: true, \/\/ \u9759\u6001\u7ec4\u4ef6 \u5f53\u4e0d\u58f0\u660efunctional\u65f6\u8be5\u7ec4\u4ef6\u540c\u6837\u62e5\u6709\u4e0a\u4e0b\u6587\u4ee5\u53ca\u751f\u547d\u5468\u671f\u51fd\u6570\n  render(createElement, context) {\n    const before = context.props.before\n    const time = context.props.time\n    const vnodeList = context.slots().default\n    if (vnodeList === undefined){\n      console.warn(&quot; \u7ec4\u4ef6\u5fc5\u987b\u8981\u6709\u5b50\u5143\u7d20&quot;)\n      return null\n    }\n    const vnode = vnodeList[0] || null \/\/ \u83b7\u53d6\u5b50\u5143\u7d20\u865a\u62dfdom\n    if (vnode.tag === &quot;input&quot;) {\n      const defaultFun = vnode.data.on.input\n      const debounceFun = debounce(defaultFun, time, before) \/\/ \u83b7\u53d6\u8282\u6d41\u51fd\u6570\n      vnode.data.on.input = debounceFun\n    } else if (vnode.tag === &quot;button&quot;) {\n      const defaultFun = vnode.data.on.click\n      const debounceFun = debounce(defaultFun, time, before) \/\/ \u83b7\u53d6\u8282\u6d41\u51fd\u6570\n      vnode.data.on.click = debounceFun\n    } else if (vnode.componentOptions &amp;&amp; vnode.componentOptions.tag === &quot;el-input&quot;) {\n      const defaultFun = vnode.componentOptions.listeners.input\n      const debounceFun = debounce(defaultFun, time, before) \/\/ \u83b7\u53d6\u8282\u6d41\u51fd\u6570\n      vnode.componentOptions.listeners.input = debounceFun\n    } else if (vnode.componentOptions &amp;&amp; vnode.componentOptions.tag === &quot;el-button&quot;) {\n      const defaultFun = vnode.componentOptions.listeners.click\n      const debounceFun = debounce(defaultFun, time, before) \/\/ \u83b7\u53d6\u8282\u6d41\u51fd\u6570\n      vnode.componentOptions.listeners.click = debounceFun\n    } else {\n      console.warn(&quot; \u7ec4\u4ef6\u5185\u53ea\u80fd\u51fa\u73b0\u4e0b\u9762\u7ec4\u4ef6\u7684\u4efb\u610f\u4e00\u4e2a\u4e14\u552f\u4e00 el-button\u3001el-input\u3001button\u3001input&quot;)\n      return vnode\n    }\n    return vnode\n  }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u539f\u7406\u4e5f\u5f88\u7b80\u5355\u5c31\u662f\u5728vNode\u4e2d\u62e6\u622aon\u4e0b\u9762\u7684click\u3001input\u4e8b\u4ef6\u505a\u9632\u6296\u5904\u7406\uff0c\u8fd9\u6837\u5728\u4f7f\u7528\u4e0a\u5c31\u975e\u5e38\u7b80\u5355\u4e86\u3002<strong>\u81ea\u5b9a\u4e49\u6307\u4ee4 directive<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6211\u4eec\u6765\u601d\u8003\u4e00\u4e2a\u95ee\u9898\uff0c\u51fd\u6570\u5f0f\u7ec4\u4ef6\u5c01\u88c5\u9632\u6296\u7684\u5173\u8282\u662f\u83b7\u53d6vNode\uff0c\u90a3\u4e48\u6211\u4eec\u901a\u8fc7\u81ea\u5b9a\u4e49\u6307\u4ee4\u540c\u6837\u53ef\u4ee5\u62ff\u5230vNode\uff0c\u751a\u81f3\u8fd8\u53ef\u4ee5\u5f97\u5230\u539f\u751f\u7684Dom\uff0c\u8fd9\u6837\u7528\u81ea\u5b9a\u4e49\u6307\u4ee4\u6765\u5904\u7406\u4f1a\u66f4\u52a0\u65b9\u4fbf\u3002\u3002\u3002\u3002\u3002\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6765\u6e90\uff1ahttps:\/\/www.ucloud.cn\/yun\/6841.html \u6458\u8981\uff1a\u6848\u4f8b\u6301\u7eed\u89e6\u53d1\u4e8b\u4ef6\u65f6\uff0c\u5e76\u4e0d\u7acb [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-109","post","type-post","status-publish","format-standard","hentry","category-1"],"_links":{"self":[{"href":"https:\/\/gd.patchouli-go.cn\/index.php?rest_route=\/wp\/v2\/posts\/109","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gd.patchouli-go.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gd.patchouli-go.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gd.patchouli-go.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gd.patchouli-go.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=109"}],"version-history":[{"count":2,"href":"https:\/\/gd.patchouli-go.cn\/index.php?rest_route=\/wp\/v2\/posts\/109\/revisions"}],"predecessor-version":[{"id":112,"href":"https:\/\/gd.patchouli-go.cn\/index.php?rest_route=\/wp\/v2\/posts\/109\/revisions\/112"}],"wp:attachment":[{"href":"https:\/\/gd.patchouli-go.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=109"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gd.patchouli-go.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=109"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gd.patchouli-go.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=109"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}