{"id":10454,"date":"2022-06-19T23:04:41","date_gmt":"2022-06-19T15:04:41","guid":{"rendered":"https:\/\/www.zhangxinxu.com\/wordpress\/?p=10454"},"modified":"2022-06-20T23:09:03","modified_gmt":"2022-06-20T15:09:03","slug":"js-extend-class-custom-elements","status":"publish","type":"post","link":"https:\/\/www.zhangxinxu.com\/wordpress\/2022\/06\/js-extend-class-custom-elements\/","title":{"rendered":"\u5982\u4f55\u7ee7\u627f\u81ea\u5b9a\u4e49\u5143\u7d20\u53ca\u5176\u4ed6JS\u4e2d\u6269\u5c55\u65b0\u65b9\u6cd5"},"content":{"rendered":"<p>by <a href=\"https:\/\/www.zhangxinxu.com\/\">zhangxinxu<\/a> from <a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=10454\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=10454<\/a> \u946b\u7a7a\u95f4-\u946b\u751f\u6d3b<br \/>\n\u672c\u6587\u6b22\u8fce\u5206\u4eab\u4e0e\u805a\u5408\uff0c\u5168\u6587\u8f6c\u8f7d\u5c31\u4e0d\u5fc5\u4e86\uff0c\u5c0a\u91cd\u7248\u6743\uff0c\u5708\u5b50\u5c31\u8fd9\u4e48\u5927\uff0c\u82e5\u6025\u7528\u53ef\u4ee5\u8054\u7cfb\u6388\u6743\u3002<\/p>\n<p><script>window.wxShareImgUrl = 'https:\/\/www.zhangxinxu.com\/study\/image\/share\/202206-class-extends.png';<\/script><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202206\/class-extends-cover.png\" width=\"480\" height=\"297\" alt=\"\u5360\u4f4d\u5c01\u9762\u56fe\" class=\"alignright clip thumb size-medium\" \/><\/p>\n<h3>\u4e00\u3001Web\u7ec4\u4ef6\u4ee5\u65e7\u6362\u65b0<\/h3>\n<p>\u4e5f\u5c31\u662f\u5982\u4f55\u4f7f\u7528\u5df2\u6709\u81ea\u5b9a\u4e49\u5143\u7d20\u7ec4\u4ef6\u521b\u5efa\u65b0\u7684\u81ea\u5b9a\u4e49\u5143\u7d20\u7ec4\u4ef6\u3002<\/p>\n<p>\u4f8b\u5982\u6709\u4e00\u4e2a A \u7ec4\u4ef6\uff0c\u8fd0\u884c\u5f88OK\uff0c\u7136\u540e\u6709\u4e00\u4e2a B \u7ec4\u4ef6\uff0c\u867d\u7136\u8bed\u4e49\u548c A \u7ec4\u4ef6\u76f8\u5dee\u751a\u8fdc\uff0c\u4f46\u662f\u529f\u80fd\u6838\u5fc3\u5374\u662f\u4e00\u81f4\u7684\u3002<\/p>\n<p>\u6b64\u65f6\uff0c\u5982\u679c\u91cd\u65b0\u5f00\u653e\u4e00\u4e2a B \u7ec4\u4ef6\u5c31\u6709\u6d6a\u8d39\uff0c\u76f4\u63a5\u4f7f\u7528 A \u7ec4\u4ef6\u8bed\u4e49\u5c31\u4e0d\u5bf9\u3002<\/p>\n<p>\u6bd4\u5982\u8bf4 swipe \u5207\u6362\u548c Tab \u9009\u9879\u5361\u5207\u6362\u7684\u6838\u5fc3\u662f\u4e00\u81f4\u7684\uff0c\u5982\u679c\u5df2\u7ecf\u6709\u4e86 Tab \u7ec4\u4ef6\uff0c\u6211\u4eec\u5982\u4f55\u7528\u975e\u5e38\u7b80\u5355\u7684\u65b9\u5f0f\u91cd\u65b0\u5b9e\u73b0\u4e00\u4e2a Swipe \u8f6e\u64ad\u7ec4\u4ef6\u5462\uff1f<\/p>\n<p>\u8fd9\u5c31\u662f\u8fd9\u91cc\u8981\u63a2\u8ba8\u7684\u5b9e\u73b0\u3002<\/p>\n<h4>Toast \u63d0\u793a\u7ec4\u4ef6\u793a\u610f<\/h4>\n<p>\u4e0d\u8fc7\u9009\u9879\u5361\u6548\u679c\u76f8\u5bf9\u6bd4\u8f83\u590d\u6742\uff0c\u7528\u6765\u505a\u6848\u4f8b\u4e0d\u5408\u9002\uff0c\u6240\u4ee5\u8fd9\u91cc\u4f7f\u7528 toast \u7ec4\u4ef6\u505a\u793a\u610f\u3002<\/p>\n<p>\u901a\u5e38 Toast \u63d0\u793a\u7ec4\u4ef6\u90fd\u662f\u63d0\u793a\u6587\u5b57\u5185\u5bb9\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202206\/2022-06-19_184350.png\" width=\"390\" height=\"198\" alt=\"Toast \u6587\u5b57\u63d0\u793a\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u7136\u540e\uff0cLoading \u6548\u679c\uff0c\u5c31\u662f\u4e0b\u56fe\u6240\u793a\u7684\u52a0\u8f7d\u52a8\u753b\u6548\u679c\uff0c\u795e\u4f3c Toast \u63d0\u793a\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202206\/2022-06-19_185154.png\" width=\"240\" height=\"295\" alt=\"loading iOS \u793a\u610f\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u56e0\u6b64\uff0c\u5f88\u591a\u7ec4\u4ef6\u628a\u8fd9\u4e2a\u5168\u5c40\u7684 loading \u63d0\u793a\u6548\u679c\u96c6\u6210\u5230\u4e86 Toast \u7ec4\u4ef6\u4e2d\u3002<\/p>\n<p>\u4ece\u529f\u80fd\u4e0a\u8bf4\uff0c\u4e0d\u662f\u4e0d\u53ef\u4ee5\uff0c\u4f46\u662f\u4ece\u8bed\u4e49\uff0c\u4ee5\u53ca\u7ec4\u4ef6\u7ba1\u7406\u7684\u89d2\u5ea6\u8bb2\uff0c\u8fd9\u4e2a\u63d0\u793a\u5e94\u8be5\u5f52\u5c5e\u4e8e Loading \u7ec4\u4ef6\u624d\u5408\u9002\u3002<\/p>\n<p>\u6b64\u65f6\uff0c\u53ef\u4ee5\u91c7\u7528\u7ec4\u4ef6\u7ee7\u627f\u7684\u65b9\u5f0f\uff0c\u81ea\u5b9a\u4e49\u4e24\u4e2a\u5b8c\u5168\u4e0d\u540c\u7684\u81ea\u5b9a\u4e49\u5143\u7d20\u7ec4\u4ef6\u3002<\/p>\n<h4>\u4ee3\u7801\u793a\u610f<\/h4>\n<p>\u5047\u8bbe\u6709\u4e2a\u540d\u4e3a zxx-toast.js \u7684\u6587\u4ef6\uff0c\u6587\u4ef6\u4e2d\u7684 JS \u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff0c\u7528\u6765\u81ea\u5b9a\u4e49 <code>&lt;zxx-toast&gt;<\/code> \u5143\u7d20\uff1a<\/p>\n<pre>\/\/ \u5b9a\u4e49 &lt;zxx-toast&gt; \u5143\u7d20\r\nclass ZxxToast extends HTMLElement {\r\n    static get observedAttributes () {\r\n        return ['open'];\r\n    }\r\n    constructor () {\r\n        super();\r\n    }\r\n    get open () {\r\n        return this.hasAttribute('open');\r\n    }\r\n\r\n    set open (val) {\r\n        this.toggleAttribute('open', val);\r\n    }\r\n    \r\n    render () {\r\n        setTimeout(() =&gt; {\r\n            this.hide();\r\n        }, 3000);\r\n    }\r\n    \r\n    show () {\r\n        this.open = true;\r\n    }\r\n\r\n    hide () {\r\n        this.open = false;    \r\n    }\r\n    \r\n    attributeChangedCallback (name, oldval, newval) {\r\n        if (name == 'open' &amp;&amp; this.open) {\r\n            this.render();\r\n        }\r\n    }\r\n}\r\n\r\nif (!customElements.get('zxx-toast')) {\r\n    customElements.define('zxx-toast', ZxxToast);\r\n}\r\n\r\nexport default ZxxToast;<\/pre>\n<p>\u5b9e\u73b0\u4e86\u975e\u5e38\u57fa\u7840\u7684\u80fd\u529b\uff0c\u5b9a\u4e49\u4e86\u4e00\u4e2a\u81ea\u5b9a\u4e49\u5c5e\u6027 <code>open<\/code>\uff0c\u5b9a\u4e49\u4e86 <code>show()<\/code> \u548c <code>hide()<\/code> \u663e\u9690\u65b9\u6cd5\uff0c\u5b9a\u4e49\u4e86 <code>render()<\/code> \u65b9\u6cd5\uff0c\u5728\u63d0\u793a\u5143\u7d20\u663e\u793a\u7684\u65f6\u5019\u6267\u884c\u3002<\/p>\n<p>\u6b64\u65f6\uff0c\u6211\u4eec\u60f3\u8981\u5b9e\u73b0\u5168\u5c4f loading \u6548\u679c\uff0c\u5219\u53ef\u4ee5\u5b8c\u5168\u7ee7\u627f\u8fd9\u91cc\u7684 ZxxToast\uff0c\u7136\u540e\u91cd\u65b0\u5b9a\u4e49\u4e00\u4e2a\u65b0\u7684\u81ea\u5b9a\u4e49\u5143\u7d20\uff0c\u4f8b\u5982 <code>&lt;zxx-loading&gt;<\/code>\uff0c\u5219\u53ef\u4ee5\u8fd9\u4e48\u505a\u3002<\/p>\n<pre>\/\/ \u5b9a\u4e49 &lt;zxx-loading&gt; \u5143\u7d20\r\nimport ZxxToast from '.\/zxx-toast.js';\r\nclass ZxxLoading extends ZxxToast {\r\n    render () {\r\n        \/\/ \u663e\u793a loading \u5185\u5bb9\r\n        this.innerHTML = '&lt;i class=\"spin\"&gt;&lt;\/i&gt;';\r\n    }\r\n}\r\nif (!customElements.get('zxx-loading')) {\r\n    customElements.define('zxx-loading', ZxxLoading);\r\n}<\/pre>\n<p>\u4e0d\u5230\u5341\u884c\u4ee3\u7801\u5c31\u7ed3\u675f\u4e86\uff0c\u4f7f\u7528 extends \u8fdb\u884c\u7ee7\u627f\uff0c\u4f7f\u7528 <code>customElements.define()<\/code> \u65b9\u6cd5\u91cd\u65b0\u5b9a\u4e49\u4e00\u4e2a\u81ea\u5b9a\u4e49\u5143\u7d20\u3002<\/p>\n<p>\u6b64\u65f6\uff0c<code>&lt;zxx-toast&gt;<\/code> \u7ec4\u4ef6\u5143\u7d20\u7684 <code>open<\/code> \u5c5e\u6027\uff0c\u4ee5\u53ca <code>show()<\/code> \u548c <code>hide()<\/code> \u65b9\u6cd5\u5168\u90e8\u90fd\u7ee7\u627f\u8fc7\u6765\u4e86\u3002<\/p>\n<p>\u5bf9\u4e8e\u4e0d\u4e00\u6837\u7684\u65b9\u6cd5\uff0c\u76f4\u63a5\u540c\u540d\u8986\u76d6\uff0c\u5bf9\u4e8e\u65b0\u65b9\u6cd5\uff0c\u76f4\u63a5\u8bbe\u7f6e\uff0c\u975e\u5e38\u7075\u6d3b\u3002<\/p>\n<p>\u6700\u540e\uff0c\u53ea\u8981\u518d\u628a\u5bf9\u5e94\u7684\u81ea\u5b9a\u4e49\u5143\u7d20\u7684 CSS \u6837\u5f0f\u8865\u4e0a\uff0c\u6211\u4eec\u7684\u9700\u6c42\u5c31\u5b9e\u73b0\u4e86\u3002<\/p>\n<h4>\u8fd0\u884c\u6d4b\u8bd5<\/h4>\n<p>\u773c\u89c1\u4e3a\u5b9e\uff0c\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/study\/202206\/custom-elements-class-extend-demo.php\" rel=\"noopener\" target=\"_blank\">Web\u7ec4\u4ef6\u7ee7\u627f\u4e3a\u65b0\u7684\u81ea\u5b9a\u4e49\u5143\u7d20\u7ec4\u4ef6demo<\/a><\/p>\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u70b9\u51fb\u4e0b\u9762\u7684\u6309\u94ae\uff0cToast \u63d0\u793a\u6b63\u5e38\u51fa\u73b0\uff0c3s \u540e\u81ea\u52a8\u6d88\u5931\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202206\/2022-06-19_195701.png\" width=\"414\" height=\"332\" alt=\"toast \u51fa\u73b0\u6548\u679c\u793a\u610f\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u800c\u70b9\u51fb loading \u663e\u793a\u6309\u94ae\uff0c\u5219\u662f\u4e0b\u56fe\u6240\u793a\u7684\u6548\u679c\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202206\/2022-06-19_195835.png\" width=\"389\" height=\"306\" alt=\"\u52a0\u8f7d\u6309\u94ae\u663e\u793a\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u4e24\u79cd\u6548\u679c\uff0c\u4e00\u4e2a\u7528\u7684\u662f <code>&lt;zxx-toast&gt;<\/code> \u5143\u7d20\uff0c\u53e6\u5916\u4e00\u4e2a\u4f7f\u7528\u7684\u662f <code>&lt;zxx-loading&gt;<\/code> \u5143\u7d20\uff0c\u770b\u8d77\u6765\u662f\u5b8c\u5168\u4e0d\u540c\u7684\u7ec4\u4ef6\uff0c\u4f46\u5b9e\u9645\u4e0a\u5185\u6838\u4ee3\u7801\u7528\u7684\u90fd\u662f\u540c\u4e00\u5957\uff0c\u4e8e\u662f\u65e2\u517c\u987e\u4e86\u53ef\u7ef4\u62a4\u6027\uff0c\u53c8\u517c\u987e\u4e86\u8bed\u4e49\u3002<\/p>\n<h3>\u4e8c\u3001Web\u7ec4\u4ef6\u9526\u4e0a\u6dfb\u82b1<\/h3>\n<p>\u4e5f\u5c31\u662f\u4e0d\u521b\u5efa\u65b0\u7684\u81ea\u5b9a\u4e49\u5143\u7d20\u7ec4\u4ef6\uff0c\u4f46\u662f\u9700\u8981\u628a\u539f\u6765\u7684Web Components\u7ec4\u4ef6\u8fdb\u884c\u589e\u5f3a\u6269\u5c55\uff0c\u53d8\u5f97\u66f4\u5389\u5bb3\u3002<\/p>\n<p>\u4f20\u7edf\u7684\u65b9\u6cd5\uff0c\u8fd9\u79cd\u589e\u5f3a\u6269\u5c55\u53ef\u80fd\u96c6\u6210\u5728\u539f\u6765\u7684\u7ec4\u4ef6 JS \u6587\u4ef6\u4e2d\u3002<\/p>\n<p>\u5176\u5b9e\uff0c\u5982\u679c\u8fd9\u79cd\u589e\u5f3a\u80fd\u529b\u5e76\u4e0d\u662f\u975e\u5e38\u5e38\u7528\uff0c\u6216\u8005\u8bf4\u4e3a\u4e86\u7ef4\u62a4\u66f4\u65b9\u4fbf\uff0c\u56e0\u4e3a\u72ec\u7acb\u7ba1\u7406\uff0c\u5176\u5b9e\u662f\u53ef\u4ee5\u5728\u53e6\u5916\u7684 JS \u4e2d\u5904\u7406\u7684\u3002<\/p>\n<p>\u5982\u679c\u8981\u4f7f\u7528\uff0c\u5c31 import \u6b64 JS\uff0c\u5982\u679c\u4e0d\u9700\u8981\u8fd9\u4e9b\u6269\u5c55\u80fd\u529b\uff0c\u8fd8\u662f import \u6838\u5fc3 JS \u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u5b9e\u73b0\u793a\u610f\uff0c\u5bf9\u4e0a\u9762\u5b9e\u73b0\u7684\u5e38\u89c4\u7684 toast \u63d0\u793a\u57fa\u7840\u4e0a\u589e\u52a0\u51e0\u4e2a\u65b9\u6cd5\uff0c\u8868\u793a\u6210\u529f\u63d0\u793a\u3001\u5931\u8d25\u63d0\u793a\u548c\u8b66\u544a\u63d0\u793a\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u6709\u4e00\u4e2a\u540d\u4e3a toast-extend.js \u7684\u6587\u4ef6\uff0c\u91cc\u9762\u6709\u5982\u4e0b\u6240\u793a\u7684 JavaScript \u4ee3\u7801\uff1a<\/p>\n<pre>\/\/ \u6269\u5c55 toast \u65b9\u6cd5\u5143\u7d20\r\nimport Toast from '.\/zxx-toast.js';\r\n\r\nToast.prototype.success = function (content) {\r\n    if (content) {\r\n        this.innerHTML = content;\r\n    }\r\n    this.setAttribute('type', 'success');\r\n    this.show();\r\n}\r\n\r\nToast.prototype.error = function (content) {\r\n    if (content) {\r\n        this.innerHTML = content;\r\n    }\r\n    this.setAttribute('type', 'error');\r\n    this.show();\r\n}\r\n\r\nToast.prototype.warning = function (content) {\r\n    if (content) {\r\n        this.innerHTML = content;\r\n    }\r\n    this.setAttribute('type', 'warning');\r\n    this.show();\r\n}\r\n\r\nexport default Toast;\r\n<\/pre>\n<p>\u6b64\u65f6\uff0c<code>&lt;zxx-toast&gt;<\/code> \u5143\u7d20\u6267\u884c success() \u4e4b\u7c7b\u7684\u65b9\u6cd5\uff0c\u5c31\u6709\u4e86\u5305\u542b\u72b6\u6001\u7684\u63d0\u793a\u6548\u679c\u4e86\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202206\/2022-06-19_222042.png\" width=\"388\" height=\"342\" alt=\"\u64cd\u4f5c\u6210\u529f\u63d0\u793a\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u773c\u89c1\u4e3a\u5b9e\uff0c\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/study\/202206\/custom-elements-class-extend-demo.php\" rel=\"noopener\" target=\"_blank\">Web\u7ec4\u4ef6\u7c7b\u6269\u5c55\u4e3a\u65b0\u7684\u7ec4\u4ef6demo<\/a><\/p>\n<h3>\u4e09\u3001\u7ad9\u5728\u5b9e\u9645\u5f00\u53d1\u7684\u89d2\u5ea6<\/h3>\n<p>\u4e0a\u9762\u4e24\u4e2a\u6848\u4f8b\u4e3b\u8981\u6f14\u793a\u5982\u4f55\u5728\u73b0\u6709\u7684 Web Components \u7ec4\u4ef6\u57fa\u7840\u4e0a\u7ee7\u627f\u4e0e\u6269\u5c55\u3002<\/p>\n<p>\u5b9e\u9645\u5f00\u53d1\u65f6\u5019\u7684\u6267\u884c\u7ec6\u8282\u4f1a\u6709\u6240\u4e0d\u540c\u3002<\/p>\n<p>\u4f8b\u5982\uff0ctoast \u7684\u51fa\u73b0\u901a\u5e38\u4e0d\u4f1a\u662f\u57fa\u4e8e <code>&lt;zxx-toast&gt;<\/code> \u5143\u7d20\uff0c\u800c\u662f\u67d0\u4e2a\u975e\u5143\u7d20\u5bf9\u8c61\u8fdb\u884c\u8c03\u7814\uff0c\u9690\u85cf DOM \u5143\u7d20\u672c\u8eab\u7684\u7ec6\u8282\u3002<\/p>\n<p>\u62ff\u4e0a\u9762\u7684 toast-extend.js \u4e3e\u4f8b\uff0c\u5bf9\u5f00\u53d1\u4eba\u5458\u4f53\u9a8c\u66f4\u597d\u7684\u5904\u7406\u65b9\u5f0f\u4e0d\u662f\u7c7b\u6269\u5c55\uff0c\u800c\u662f\u76f4\u63a5\u4e00\u4e2a\u9759\u6001\u65b9\u6cd5\u66f4\u4e3a\u5408\u9002\u3002<\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre>\/\/ \u6269\u5c55 toast \u65b9\u6cd5\u5143\u7d20\r\nimport Toast from '.\/zxx-toast.js';\r\n\r\nToast.success = function (content) {\r\n    const toast = new Toast();\r\n    if (content) {\r\n        toast.innerHTML = content;\r\n    }\r\n    toast.setAttribute('type', 'success');\r\n    toast.show();\r\n    document.body.appendChild(toast);\r\n}\r\n\r\nexport default Toast;<\/pre>\n<p>\u5047\u8bbe\u4e0a\u9762\u4ee3\u7801\u5c5e\u4e8e toast-extend-static.js \uff0c\u5219\u6b64\u65f6\uff0c\u9875\u9762\u4e2d\u65e0\u9700\u4efb\u4f55\u81ea\u5b9a\u4e49\u5143\u7d20\uff0c\u76f4\u63a5\u6267\u884c\u5bf9\u5e94\u7684 success \u65b9\u6cd5\uff0c\u5bf9\u5e94\u7684 toast \u63d0\u793a\u6548\u679c\u5c31\u51fa\u73b0\u4e86\u3002<\/p>\n<p>\u793a\u610f\uff1a<\/p>\n<pre>&lt;button id=\"button\"&gt;\u6210\u529f\u63d0\u793a&lt;\/button&gt;\r\n&lt;script type=\"module\"&gt;\r\nimport Toast from '.\/toast-extends-static.js';\r\n\r\nbutton.onclick = function () {\r\n    Toast.success('\u64cd\u4f5c\u6210\u529f');\r\n};\r\n&lt;\/script&gt;<\/pre>\n<p>\u5b9e\u65f6\u6548\u679c\u5982\u4e0b\u6240\u793a\uff08iframe\u5185\u5d4c\u9875\uff0c\u5982\u679c\u6ca1\u6709\u6548\u679c\uff0c\u70b9\u51fb<a href=\"https:\/\/www.zhangxinxu.com\/study\/202206\/toast-static.html\" rel=\"noopener\" target=\"_blank\">\u8fd9\u91cc<\/a>\u9884\u89c8\uff09\uff1a<\/p>\n<p><iframe loading=\"lazy\" width=\"100%\" height=\"320\" style=\"max-width: 640px;border:1px solid #ccc;\" src=\"https:\/\/www.zhangxinxu.com\/study\/202206\/toast-static.html\" frameborder=\"0\"><\/iframe><\/p>\n<h4>\u7ed3\u8bed<\/h4>\n<p>\u597d\uff0c\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\u3002<\/p>\n<p>\u5bf9\u4e8e\u539f\u751f\u7684 Web Components \u7ec4\u4ef6\u5f00\u53d1\uff0c\u5bf9\u4e8e\u5f88\u591a\u524d\u7aef\u5f00\u53d1\u4eba\u5458\u800c\u8a00\uff0c\u662f\u6ca1\u673a\u4f1a\u5728\u751f\u4ea7\u73af\u5883\u5b9e\u8df5\u7684\u3002<\/p>\n<p>\u56e0\u4e3a\u4e1a\u754c\u6709\u5f88\u591a\u6210\u719f\u7684\u4e0a\u5c42\u7ec4\u4ef6\u6846\u67b6\uff0c\u7ad9\u5728\u4e1a\u52a1\u5f00\u53d1\u7684\u89d2\u5ea6\u800c\u8a00\uff0c\u5e76\u4e0d\u9700\u8981\u4f60\u53bb\u524d\u8a00\u548c\u5e95\u5c42\u6e38\u8d70\u3002<\/p>\n<p>\u4ee5\u53ca\uff0c\u867d\u7136\u6709\u770b\u5230\u4e0d\u5c11\u56e2\u961f\u5f00\u59cb\u62e5\u62b1 Web Components\uff0c\u4f46\u662f\uff0c\u8bf4\u5b9e\u8bdd\uff0c\u64cd\u5200\u7684\u90fd\u662f\u56e2\u961f\u4e2d\u6d41\u7825\u67f1\u7684\u8001\u624b\uff0c\u4e0d\u662f\u4f60\u60f3\u73a9\u5c31\u80fd\u73a9\u7684\u3002<\/p>\n<p>\u4f46\u662f\uff0c\u6b63\u6240\u8c13\u673a\u4f1a\u662f\u7559\u7ed9\u6709\u51c6\u5907\u7684\u4eba\u7684\uff0c\u5982\u679c\u4f60\u7684\u6280\u672f\u6210\u957f\u5168\u662f\u9760\u4e1a\u52a1\u9879\u76ee\u9a71\u52a8\uff0c\u4e0d\u53bb\u62e5\u62b1\u8fd9\u4e9b\u5176\u5b9e\u975e\u5e38\u91cd\u8981\uff0c\u4ee5\u540e\u53ef\u80fd\u4f1a\u6210\u4e3a\u4e3b\u6d41\u7684\u4e1c\u897f\uff0c\u804c\u4e1a\u53d1\u5c55\u5230\u4e86\u4e00\u5b9a\u9636\u6bb5\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u9ad8\u4e0d\u6210\u4f4e\u4e0d\u5c31\u7684\u72b6\u6001\u3002<\/p>\n<p>\u4e0d\u626f\u8fdc\u4e86\uff0c\u611f\u8c22\u5927\u5bb6\u7684\u9605\u8bfb\uff0c\u5982\u679c\u89c9\u5f97\u672c\u6587\u7684\u5185\u5bb9\u5bf9\u4f60\u7684\u5de5\u4f5c\u6709\u6240\u5e2e\u52a9\uff0c\u6b22\u8fce<button onclick=\"shareWeixin.click()\" class=\"entry-share-btn\">\u5206\u4eab<\/button>\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/emtion\/emoji\/2764.svg\" width=\"20\" height=\"20\" align=\"absmiddle\"><\/p>\n<p>\u672c\u6587\u4e3a\u539f\u521b\u6587\u7ae0\uff0c\u6b22\u8fce\u5206\u4eab\uff0c\u52ff\u5168\u6587\u8f6c\u8f7d\uff0c\u5982\u679c\u5b9e\u5728\u559c\u6b22\uff0c\u53ef\u6536\u85cf\uff0c\u6c38\u4e0d\u8fc7\u671f\uff0c\u4e14\u4f1a\u53ca\u65f6\u66f4\u65b0\u77e5\u8bc6\u70b9\u53ca\u4fee\u6b63\u9519\u8bef\uff0c\u9605\u8bfb\u4f53\u9a8c\u4e5f\u66f4\u597d\u3002<br \/>\n\u672c\u6587\u5730\u5740\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=10454\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=10454<\/a><\/p>\n<p>\uff08\u672c\u7bc7\u5b8c\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202206\/class-extends-cover.png\" width=\"160\" height=\"99\" alt=\"\u5360\u4f4d\u5c01\u9762\u56fe\" class=\"alignright size-medium\" loading=\"lazy\" \/><\/p>\n<p>\u76f8\u4f3c\u5185\u6838\u4f46\u8bed\u4e49\u4e0d\u540c\u7684Web\u7ec4\u4ef6\u8be5\u5982\u4f55\u66f4\u9ad8\u6548\u7684\u7ec4\u7ec7\u4ee3\u7801\u624d\u80fd\u517c\u987e\u53ef\u7ef4\u62a4\u6027\u548c\u53ef\u9605\u8bfb\u6027\u5462\uff1f\u5982\u4f55\u5728\u4efb\u610f\u4f4d\u7f6e\u5bf9\u5df2\u7531\u7684\u81ea\u5b9a\u4e49\u5143\u7d20\u7ec4\u4ef6\u8fdb\u884c\u65b9\u6cd5\u6216\u5c5e\u6027\u7684\u6269\u5c55\u5462\uff1f\u4e00\u70b9\u5b9e\u6218\u7ecf\u9a8c\u5206\u4eab\uff0c\u5e0c\u671b\u53ef\u4ee5\u5e2e\u5230\u5927\u5bb6\u7684\u5de5\u4f5c\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[180],"tags":[195,1554,1839,828,1556,1222,449,1223],"_links":{"self":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/10454"}],"collection":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/comments?post=10454"}],"version-history":[{"count":0,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/10454\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/media?parent=10454"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/categories?post=10454"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/tags?post=10454"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}