{"id":66421,"date":"2024-10-14T17:22:19","date_gmt":"2024-10-14T09:22:19","guid":{"rendered":"https:\/\/server.hk\/cnblog\/66421\/"},"modified":"2024-10-14T17:22:19","modified_gmt":"2024-10-14T09:22:19","slug":"mui%e8%a8%bb%e5%86%8a%e9%a0%81%e9%9d%a2%e8%88%87%e6%95%b8%e6%93%9a%e5%ba%ab%e7%9a%84%e5%ae%8c%e7%be%8e%e7%b5%90%e5%90%88-mui%e8%a8%bb%e5%86%8a%e9%a0%81%e9%9d%a2%e8%88%87%e6%95%b8%e6%93%9a%e5%ba%ab","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/66421\/","title":{"rendered":"MUI\u8a3b\u518a\u9801\u9762\u8207\u6578\u64da\u5eab\u7684\u5b8c\u7f8e\u7d50\u5408 (mui\u8a3b\u518a\u9801\u9762\u8207\u6578\u64da\u5eab)"},"content":{"rendered":"<h1 id=\"mui%e8%a8%bb%e5%86%8a%e9%a0%81%e9%9d%a2%e8%88%87%e6%95%b8%e6%93%9a%e5%ba%ab%e7%9a%84%e5%ae%8c%e7%be%8e%e7%b5%90%e5%90%88-dQPXdYHbRy\">MUI\u8a3b\u518a\u9801\u9762\u8207\u6578\u64da\u5eab\u7684\u5b8c\u7f8e\u7d50\u5408<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u7db2\u7d61\u74b0\u5883\u4e2d\uff0c\u8a3b\u518a\u9801\u9762\u662f\u7528\u6236\u8207\u61c9\u7528\u7a0b\u5e8f\u4e92\u52d5\u7684\u7b2c\u4e00\u6b65\u3002\u96a8\u8457\u524d\u7aef\u6280\u8853\u7684\u767c\u5c55\uff0cMaterial-UI\uff08MUI\uff09\u4f5c\u70ba\u4e00\u500b\u6d41\u884c\u7684React UI\u6846\u67b6\uff0c\u70ba\u958b\u767c\u8005\u63d0\u4f9b\u4e86\u8c50\u5bcc\u7684\u7d44\u4ef6\u548c\u8a2d\u8a08\u98a8\u683c\uff0c\u4f7f\u5f97\u8a3b\u518a\u9801\u9762\u7684\u958b\u767c\u8b8a\u5f97\u66f4\u52a0\u9ad8\u6548\u548c\u7f8e\u89c0\u3002\u7136\u800c\uff0c\u50c5\u50c5\u64c1\u6709\u4e00\u500b\u5438\u5f15\u4eba\u7684\u524d\u7aef\u754c\u9762\u662f\u4e0d\u5920\u7684\uff0c\u5f8c\u7aef\u6578\u64da\u5eab\u7684\u652f\u6301\u540c\u6a23\u81f3\u95dc\u91cd\u8981\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5982\u4f55\u5c07MUI\u8a3b\u518a\u9801\u9762\u8207\u6578\u64da\u5eab\u5b8c\u7f8e\u7d50\u5408\uff0c\u4ee5\u5be6\u73fe\u9ad8\u6548\u7684\u7528\u6236\u8a3b\u518a\u6d41\u7a0b\u3002<\/p>\n<h2 id=\"mui%e8%a8%bb%e5%86%8a%e9%a0%81%e9%9d%a2%e7%9a%84%e8%a8%ad%e8%a8%88-dQPXdYHbRy\">MUI\u8a3b\u518a\u9801\u9762\u7684\u8a2d\u8a08<\/h2>\n<p>MUI\u63d0\u4f9b\u4e86\u591a\u7a2e\u7d44\u4ef6\u4f86\u69cb\u5efa\u8a3b\u518a\u9801\u9762\uff0c\u5305\u62ec\u6587\u672c\u6846\u3001\u6309\u9215\u548c\u9078\u64c7\u6846\u7b49\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684\u8a3b\u518a\u8868\u55ae\u793a\u4f8b\uff1a<\/p>\n<pre><code>\nimport React from 'react';\nimport { TextField, Button, Container } from '@mui\/material';\n\nconst RegisterForm = () =&gt; {\n    return (\n        \n            <h2 id=\"%e8%a8%bb%e5%86%8a-dQPXdYHbRy\">\u8a3b\u518a<\/h2>\n            \n                \n                \n                \n                <Button type=\"submit\">\u63d0\u4ea4<\/Button>\n            \n        \n    );\n};\n\nexport default RegisterForm;\n<\/code><\/pre>\n<p>\u5728\u9019\u500b\u793a\u4f8b\u4e2d\uff0c\u6211\u5011\u4f7f\u7528\u4e86MUI\u7684<code>TextField<\/code>\u548c<code>Button<\/code>\u7d44\u4ef6\u4f86\u69cb\u5efa\u8a3b\u518a\u8868\u55ae\u3002\u9019\u4e9b\u7d44\u4ef6\u4e0d\u50c5\u7f8e\u89c0\uff0c\u9084\u5177\u6709\u826f\u597d\u7684\u7528\u6236\u9ad4\u9a57\u3002<\/p>\n<h2 id=\"%e6%95%b8%e6%93%9a%e5%ba%ab%e7%9a%84%e8%a8%ad%e7%bd%ae-dQPXdYHbRy\">\u6578\u64da\u5eab\u7684\u8a2d\u7f6e<\/h2>\n<p>\u5728\u524d\u7aef\u8a2d\u8a08\u5b8c\u6210\u5f8c\uff0c\u63a5\u4e0b\u4f86\u9700\u8981\u8a2d\u7f6e\u5f8c\u7aef\u6578\u64da\u5eab\u4f86\u5b58\u5132\u7528\u6236\u7684\u8a3b\u518a\u4fe1\u606f\u3002\u5e38\u898b\u7684\u6578\u64da\u5eab\u9078\u64c7\u5305\u62ecMySQL\u3001PostgreSQL\u548cMongoDB\u7b49\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528Node.js\u548cExpress\u6846\u67b6\u9023\u63a5MySQL\u6578\u64da\u5eab\u7684\u57fa\u672c\u6b65\u9a5f\uff1a<\/p>\n<pre><code>\nconst express = require('express');\nconst mysql = require('mysql');\nconst bodyParser = require('body-parser');\n\nconst app = express();\napp.use(bodyParser.json());\n\nconst db = mysql.createConnection({\n    host: 'localhost',\n    user: 'root',\n    password: 'password',\n    database: 'user_db'\n});\n\ndb.connect(err =&gt; {\n    if (err) throw err;\n    console.log('\u6578\u64da\u5eab\u5df2\u9023\u63a5');\n});\n\napp.post('\/register', (req, res) =&gt; {\n    const { username, email, password } = req.body;\n    const sql = 'INSERT INTO users (username, email, password) VALUES (?, ?, ?)';\n    db.query(sql, [username, email, password], (err, result) =&gt; {\n        if (err) throw err;\n        res.send('\u7528\u6236\u8a3b\u518a\u6210\u529f');\n    });\n});\n\napp.listen(3000, () =&gt; {\n    console.log('\u4f3a\u670d\u5668\u904b\u884c\u57283000\u7aef\u53e3');\n});\n<\/code><\/pre>\n<p>\u5728\u9019\u6bb5\u4ee3\u78bc\u4e2d\uff0c\u6211\u5011\u8a2d\u7f6e\u4e86\u4e00\u500b\u7c21\u55ae\u7684Express\u4f3a\u670d\u5668\uff0c\u4e26\u9023\u63a5\u5230MySQL\u6578\u64da\u5eab\u3002\u7576\u7528\u6236\u63d0\u4ea4\u8a3b\u518a\u8868\u55ae\u6642\uff0c\u6578\u64da\u5c07\u88ab\u63d2\u5165\u5230\u6578\u64da\u5eab\u4e2d\u3002<\/p>\n<h2 id=\"%e5%89%8d%e5%be%8c%e7%ab%af%e7%9a%84%e7%b5%90%e5%90%88-dQPXdYHbRy\">\u524d\u5f8c\u7aef\u7684\u7d50\u5408<\/h2>\n<p>\u70ba\u4e86\u5be6\u73fe\u524d\u5f8c\u7aef\u7684\u5b8c\u7f8e\u7d50\u5408\uff0c\u6211\u5011\u9700\u8981\u5728MUI\u8a3b\u518a\u9801\u9762\u4e2d\u6dfb\u52a0\u4e00\u500b\u63d0\u4ea4\u4e8b\u4ef6\u8655\u7406\u51fd\u6578\uff0c\u5c07\u7528\u6236\u8f38\u5165\u7684\u6578\u64da\u767c\u9001\u5230\u5f8c\u7aefAPI\uff1a<\/p>\n<pre><code>\nconst handleSubmit = async (event) =&gt; {\n    event.preventDefault();\n    const data = {\n        username: event.target.username.value,\n        email: event.target.email.value,\n        password: event.target.password.value,\n    };\n\n    const response = await fetch('\/register', {\n        method: 'POST',\n        headers: {\n            'Content-Type': 'application\/json',\n        },\n        body: JSON.stringify(data),\n    });\n\n    if (response.ok) {\n        alert('\u8a3b\u518a\u6210\u529f');\n    } else {\n        alert('\u8a3b\u518a\u5931\u6557');\n    }\n};\n<\/code><\/pre>\n<p>\u9019\u6a23\uff0c\u7576\u7528\u6236\u63d0\u4ea4\u8a3b\u518a\u8868\u55ae\u6642\uff0c\u6578\u64da\u5c07\u88ab\u767c\u9001\u5230\u5f8c\u7aef\uff0c\u4e26\u5b58\u5132\u5728\u6578\u64da\u5eab\u4e2d\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-dQPXdYHbRy\">\u7e3d\u7d50<\/h2>\n<p>\u901a\u904e\u5c07MUI\u8a3b\u518a\u9801\u9762\u8207\u6578\u64da\u5eab\u7d50\u5408\uff0c\u6211\u5011\u53ef\u4ee5\u5275\u5efa\u4e00\u500b\u9ad8\u6548\u4e14\u7f8e\u89c0\u7684\u7528\u6236\u8a3b\u518a\u6d41\u7a0b\u3002MUI\u7684\u7d44\u4ef6\u4f7f\u5f97\u524d\u7aef\u958b\u767c\u8b8a\u5f97\u7c21\u55ae\uff0c\u800c\u5f8c\u7aef\u6578\u64da\u5eab\u7684\u652f\u6301\u5247\u78ba\u4fdd\u4e86\u6578\u64da\u7684\u5b89\u5168\u5b58\u5132\u3002\u9019\u7a2e\u524d\u5f8c\u7aef\u7684\u5354\u4f5c\u4e0d\u50c5\u63d0\u5347\u4e86\u7528\u6236\u9ad4\u9a57\uff0c\u4e5f\u70ba\u958b\u767c\u8005\u63d0\u4f9b\u4e86\u9748\u6d3b\u6027\u548c\u64f4\u5c55\u6027\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u7a69\u5b9a\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\u4f86\u652f\u6301\u60a8\u7684\u61c9\u7528\u7a0b\u5e8f\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u6eff\u8db3\u4e0d\u540c\u9700\u6c42\u3002\u7121\u8ad6\u662f <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u9084\u662f\u5176\u4ed6\u670d\u52d9\uff0c\u6211\u5011\u90fd\u80fd\u70ba\u60a8\u63d0\u4f9b\u53ef\u9760\u7684\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22MUI\u8a3b\u518a\u9801\u9762\u8207\u6578\u64da\u5eab\u7684\u5b8c\u7f8e\u7d50\u5408\uff0c\u5be6\u73fe\u9ad8\u6548\u7528\u6236\u8a3b\u518a\u8207\u6578\u64da\u7ba1\u7406\uff0c\u63d0\u5347\u61c9\u7528\u6027\u80fd\u8207\u7528\u6236\u9ad4\u9a57\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-66421","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/66421","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=66421"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/66421\/revisions"}],"predecessor-version":[{"id":66422,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/66421\/revisions\/66422"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=66421"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=66421"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=66421"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}