{"id":28190,"date":"2024-11-24T12:39:44","date_gmt":"2024-11-24T04:39:44","guid":{"rendered":"https:\/\/fwq.ai\/blog\/28190\/"},"modified":"2024-11-24T12:39:44","modified_gmt":"2024-11-24T04:39:44","slug":"%e4%b8%8d%e8%a6%81%e4%be%9d%e8%b5%96%e9%bb%98%e8%ae%a4%e5%b1%9e%e6%80%a7%e5%80%bc%e6%9d%a5%e8%ae%be%e7%bd%ae-web-%e7%bb%84%e4%bb%b6%e7%9a%84%e6%a0%b7%e5%bc%8f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/28190\/","title":{"rendered":"\u4e0d\u8981\u4f9d\u8d56\u9ed8\u8ba4\u5c5e\u6027\u503c\u6765\u8bbe\u7f6e Web \u7ec4\u4ef6\u7684\u6837\u5f0f"},"content":{"rendered":"<p>\u522b\u8bef\u4f1a\u6211\u7684\u610f\u601d\uff0c\u6211\u5e76\u4e0d\u53cd\u5bf9 web \u7ec4\u4ef6 api \u7684\u9ed8\u8ba4\u503c\u3002\u6211\u5bf9\u4ed6\u4eec\u7684\u95ee\u9898\u662f\u4ed6\u4eec\u4e0d\u53ef\u9760\u3002 <\/p>\n<h2> \u95ee\u9898 <\/h2>\n<p>\u4e3a api \u63d0\u4f9b\u53ef\u7528\u9009\u9879\u5217\u8868\u7684\u5e38\u89c1\u65b9\u6cd5\u662f\u4f7f\u7528  \u7684 untion \u7c7b\u578b\u3002<\/p>\n<pre>\/** the display variant for the button *\/\n@property({reflect: true})\nvariant: 'default' | 'solid' | 'ghost' = 'default';\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u91cc\u6709\u4e00\u4e9b\u57fa\u672c\u7684  \u6765\u4f7f\u8fd9\u4e9b\u53d8\u4f53\u53d1\u6325\u4f5c\u7528\u3002<\/p>\n<pre>:host {\n  --accent-color: #0265dc;\n}\n\nbutton {\n  cursor: pointer;\n  padding: 0.5rem;\n}\n\n:host([variant='default']) button {\n  border: solid 1px var(--accent-color);\n  background-color: white;\n  color: var(--accent-color);\n}\n\n:host([variant='solid']) button {\n  border: solid 1px var(--accent-color);\n  background-color: var(--accent-color);\n  color: white;\n}\n\n:host([variant='ghost']) button {\n  border: solid 1px transparent;\n  background-color: transparent;\n  color: var(--accent-color);\n}\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<blockquote><p>\n  \u6ce8\u610f\uff1a\u4ee3\u7801\u793a\u4f8b\u4f7f\u7528 lit\uff0c\u4f46\u8fd9\u91cc\u8ba8\u8bba\u7684\u539f\u7406\u53ef\u4ee5\u8f7b\u677e\u5e94\u7528\u4e8e\u5176\u4ed6\u5e93\u548c\u6846\u67b6\u3002\n<\/p><\/blockquote>\n<p>\u6311\u6218\u662f\u81ea\u5b9a\u4e49\u5143\u7d20\/web \u7ec4\u4ef6\u53ef\u4ee5\u5728\u4efb\u4f55\u5730\u65b9\u4f7f\u7528\u3002\u5b83\u4eec\u53ef\u4ee5\u4ee5\u5b57\u7b26\u4e32\u3001\u670d\u52a1\u5668\u7aef\u8bed\u8a00\uff08\u5982 php\uff09\u63d2\u5165\u5230 dom \u4e2d\uff0c\u53ef\u4ee5\u5728 javascript \u7684 createelement \u51fd\u6570\u4e2d\u521b\u5efa\uff0c\u751a\u81f3\u53ef\u4ee5\u5728\u6807\u51c6 html \u4e2d\u521b\u5efa\u3002\u6211\u7684\u610f\u601d\u662f\uff0c\u5e76\u4e0d\u603b\u662f\u6709\u4e00\u79cd\u201c\u7c7b\u578b\u5b89\u5168\u201d\u7684\u65b9\u6cd5\u6765\u786e\u4fdd\u51c6\u786e\u8bbe\u7f6e\u81ea\u5b9a\u4e49\u5143\u7d20\u5c5e\u6027\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u7ec4\u4ef6\u5e93\u7684 pr \u6e05\u5355\u4e2d\u7684\u4e00\u9879\u662f\uff1a<\/p>\n<blockquote>\n<p> \u5c5e\u6027\u548c\u5c5e\u6027\u5728\u8bbe\u7f6e\u3001\u53d6\u6d88\u8bbe\u7f6e\u548c\u8bbe\u7f6e\u4e0d\u5f53\u65f6\u90fd\u6709\u6548\u3002<\/p>\n<\/blockquote>\n<h2> \u6d4b\u8bd5\u6211\u4eec\u7684 api <\/h2>\n<p>\u6839\u636e\u8fd9\u4e9b\u51c6\u5219\uff0c\u8ba9\u6211\u4eec\u6d4b\u8bd5\u4e0a\u9762\u7684 api \u8bbe\u7f6e\u3002<\/p>\n<ul>\n<li>\u8bbe\u7f6e &#8211; \u4e00\u5207\u770b\u8d77\u6765\u90fd\u5f88\u597d\u3002 <\/li>\n<\/ul>\n<pre>&lt;my-button variant=\"default\"&gt;default button&lt;\/my-button&gt;\n&lt;my-button variant=\"solid\"&gt;solid button&lt;\/my-button&gt;\n&lt;my-button variant=\"ghost\"&gt;my button&lt;\/my-button&gt;\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173142327796635.jpg\" class=\"aligncenter\" title=\"\u4e0d\u8981\u4f9d\u8d56\u9ed8\u8ba4\u5c5e\u6027\u503c\u6765\u8bbe\u7f6e Web \u7ec4\u4ef6\u7684\u6837\u5f0f\u63d2\u56fe\" alt=\"\u4e0d\u8981\u4f9d\u8d56\u9ed8\u8ba4\u5c5e\u6027\u503c\u6765\u8bbe\u7f6e Web \u7ec4\u4ef6\u7684\u6837\u5f0f\u63d2\u56fe\" \/><\/p>\n<ul>\n<li>\u672a\u8bbe\u7f6e\n<ul>\n<li>\u6ca1\u6709\u8bbe\u7f6e\u5c5e\u6027\uff0c\u5b83\u53ef\u4ee5\u6b63\u5e38\u5de5\u4f5c\uff0c\u56e0\u4e3a\u6211\u4eec\u6709\u4e00\u4e2a\u9ed8\u8ba4\u503c\uff0c\u5e76\u4e14\u5b83\u88ab\u914d\u7f6e\u4e3a\u5728\u8bbe\u7f6e\u65f6\u53cd\u6620\u5143\u7d20\u4e0a\u7684\u5c5e\u6027\u3002<\/li>\n<li>\u5982\u679c\u6211\u4eec\u5c06\u53d8\u91cf\u5c5e\u6027\u8bbe\u7f6e\u4e3a\u672a\u5b9a\u4e49\uff0c\u5219\u4f1a\u7834\u574f\u6837\u5f0f\u3002 <\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre>&lt;!-- no attribute set --&gt;\n&lt;my-button&gt;no attribute button&lt;\/my-button&gt;\n\n&lt;!-- jsx example --&gt;\n&lt;my-button variant={undefined}&gt;unset button&lt;\/my-button&gt;\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173142327894044.jpg\" class=\"aligncenter\" title=\"\u4e0d\u8981\u4f9d\u8d56\u9ed8\u8ba4\u5c5e\u6027\u503c\u6765\u8bbe\u7f6e Web \u7ec4\u4ef6\u7684\u6837\u5f0f\u63d2\u56fe1\" alt=\"\u4e0d\u8981\u4f9d\u8d56\u9ed8\u8ba4\u5c5e\u6027\u503c\u6765\u8bbe\u7f6e Web \u7ec4\u4ef6\u7684\u6837\u5f0f\u63d2\u56fe1\" \/><\/p>\n<ul>\n<li>\u8bbe\u7f6e\u4e0d\u5f53 &#8211; \u5f53\u6211\u4eec\u5c06\u53d8\u4f53\u5c5e\u6027\u8bbe\u7f6e\u4e3a\u201c\u5783\u573e\u201d\u65f6\uff0c\u5b83\u4e5f\u4f1a\u5d29\u6e83\u3002 <\/li>\n<\/ul>\n<pre>&lt;my-button variant=\"rubbish\"&gt;rubbish button&lt;\/my-button&gt;\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173142327890893.jpg\" class=\"aligncenter\" title=\"\u4e0d\u8981\u4f9d\u8d56\u9ed8\u8ba4\u5c5e\u6027\u503c\u6765\u8bbe\u7f6e Web \u7ec4\u4ef6\u7684\u6837\u5f0f\u63d2\u56fe2\" alt=\"\u4e0d\u8981\u4f9d\u8d56\u9ed8\u8ba4\u5c5e\u6027\u503c\u6765\u8bbe\u7f6e Web \u7ec4\u4ef6\u7684\u6837\u5f0f\u63d2\u56fe2\" \/><\/p>\n<p>\u60a8\u53ef\u4ee5\u5728\u8fd9\u91cc\u6d4b\u8bd5\u8fd9\u4e2a\u793a\u4f8b\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173142327857161.jpg\" class=\"aligncenter\" title=\"\u4e0d\u8981\u4f9d\u8d56\u9ed8\u8ba4\u5c5e\u6027\u503c\u6765\u8bbe\u7f6e Web \u7ec4\u4ef6\u7684\u6837\u5f0f\u63d2\u56fe3\" alt=\"\u4e0d\u8981\u4f9d\u8d56\u9ed8\u8ba4\u5c5e\u6027\u503c\u6765\u8bbe\u7f6e Web \u7ec4\u4ef6\u7684\u6837\u5f0f\u63d2\u56fe3\" \/><\/p>\n<h2> \u4fee\u590d api <\/h2>\n<p>\u89e3\u51b3\u6b64\u95ee\u9898\u7684\u6700\u7b80\u5355\u65b9\u6cd5\u662f\u4f7f\u6309\u94ae\u5143\u7d20\u6837\u5f0f\u4e0e\u9ed8\u8ba4\u6837\u5f0f\u5339\u914d\u3002<\/p>\n<pre>button {\n  border: solid 1px var(--accent-color);\n  background-color: white;\n  color: var(--accent-color);\n  cursor: pointer;\n  padding: 0.5rem;\n}\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u73b0\u5728\u6211\u4eec\u53ef\u4ee5\u5220\u9664\u9ed8\u8ba4\u53d8\u4f53\u7684\u4ee3\u7801\u3002<\/p>\n<pre>\/* we can remove this *\/\n:host([variant='default']) button {\n  border: solid 1px var(--accent-color);\n  background-color: white;\n  color: var(--accent-color);\n}\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4e3a\u4e86\u907f\u514d\u6df7\u6dc6\uff0c\u60a8\u53ef\u4ee5\u7559\u4e0b\u6837\u5f0f\u5e76\u6dfb\u52a0\u8bc4\u8bba\u3002<\/p>\n<pre>\/* styles for this variant are under the `button` element *\/\n:host([variant='default']) { }\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6211\u4eec\u8fd8\u53ef\u4ee5\u66f4\u65b0 typescript api\uff0c\u4f7f\u5176\u6210\u4e3a\u53ef\u9009\u5e76\u5220\u9664\u9ed8\u8ba4\u503c\u3002<\/p>\n<pre>\/** The display variant for the button *\/\n@property({ reflect: true })\nvariant?: 'default' | 'solid' | 'ghost';\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u73b0\u5728\uff0c\u5982\u679c\u503c\u5df2\u8bbe\u7f6e\u3001\u672a\u8bbe\u7f6e\u6216\u8bbe\u7f6e\u4e0d\u5f53\uff0c\u5143\u7d20\u7684\u884c\u4e3a\u5c06\u4fdd\u6301\u4e00\u81f4\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173142327873033.jpg\" class=\"aligncenter\" title=\"\u4e0d\u8981\u4f9d\u8d56\u9ed8\u8ba4\u5c5e\u6027\u503c\u6765\u8bbe\u7f6e Web \u7ec4\u4ef6\u7684\u6837\u5f0f\u63d2\u56fe4\" alt=\"\u4e0d\u8981\u4f9d\u8d56\u9ed8\u8ba4\u5c5e\u6027\u503c\u6765\u8bbe\u7f6e Web \u7ec4\u4ef6\u7684\u6837\u5f0f\u63d2\u56fe4\" \/><\/p>\n<p>\u60a8\u53ef\u4ee5\u5728\u6b64\u5904\u67e5\u770b\u6700\u7ec8\u4ee3\u7801\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173142327857161.jpg\" class=\"aligncenter\" title=\"\u4e0d\u8981\u4f9d\u8d56\u9ed8\u8ba4\u5c5e\u6027\u503c\u6765\u8bbe\u7f6e Web \u7ec4\u4ef6\u7684\u6837\u5f0f\u63d2\u56fe3\" alt=\"\u4e0d\u8981\u4f9d\u8d56\u9ed8\u8ba4\u5c5e\u6027\u503c\u6765\u8bbe\u7f6e Web \u7ec4\u4ef6\u7684\u6837\u5f0f\u63d2\u56fe3\" \/><\/p>\n<h2> \u7ed3\u8bba <\/h2>\n<p>\u901a\u8fc7\u5220\u9664\u5bf9\u9ed8\u8ba4\u503c\u7684\u4f9d\u8d56\uff0c\u60a8\u53ef\u4ee5\u521b\u5efa\u66f4\u5177\u5f39\u6027\u7684 web \u7ec4\u4ef6 api\u3002\u5982\u679c\u60a8\u7684\u7ec4\u4ef6\u5fc5\u987b\u5177\u6709\u9ed8\u8ba4\u503c\u624d\u80fd\u6b63\u5e38\u8fd0\u884c\uff0c\u8bf7\u52a1\u5fc5\u67e5\u770b\u672c\u6587\u4ee5\u521b\u5efa\u4e00\u81f4\u5de5\u4f5c\u7684 web \u7ec4\u4ef6\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u4e0d\u8981\u4f9d\u8d56\u9ed8\u8ba4\u5c5e\u6027\u503c\u6765\u8bbe\u7f6e Web \u7ec4\u4ef6\u7684\u6837\u5f0f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u522b\u8bef\u4f1a\u6211\u7684\u610f\u601d\uff0c\u6211\u5e76\u4e0d\u53cd\u5bf9 web \u7ec4\u4ef6 api \u7684\u9ed8\u8ba4\u503c\u3002\u6211\u5bf9\u4ed6\u4eec\u7684\u95ee\u9898\u662f\u4ed6\u4eec\u4e0d\u53ef\u9760\u3002 \u95ee\u9898 \u4e3a api \u63d0\u4f9b\u53ef\u7528\u9009\u9879\u5217\u8868\u7684\u5e38\u89c1\u65b9\u6cd5\u662f\u4f7f\u7528 \u7684 untion \u7c7b\u578b\u3002 \/** the display variant for the button *\/ @property({reflect: true}) variant: &#8216;default&#8217; | &#8216;solid&#8217; | &#8216;ghost&#8217; = &#8216;default&#8217;; \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u91cc\u6709\u4e00\u4e9b\u57fa\u672c\u7684 \u6765\u4f7f\u8fd9\u4e9b\u53d8\u4f53\u53d1\u6325\u4f5c\u7528\u3002 :host { &#8211;accent-color: #0265dc; } button { cursor: pointer; padding: 0.5rem; } :host([variant=&#8217;default&#8217;]) button { border: solid 1px var(&#8211;accent-color); background-color: white; color: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-28190","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/28190","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=28190"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/28190\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=28190"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=28190"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=28190"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}