{"id":38491,"date":"2023-06-10T05:16:20","date_gmt":"2023-01-25T03:34:54","guid":{"rendered":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8next-jstypescript%e7%9a%84%e7%8e%af%e5%a2%83%e4%b8%ad%e5%bc%95%e5%85%a5emotion%e3%80%82\/"},"modified":"2024-01-15T09:56:29","modified_gmt":"2024-01-15T01:56:29","slug":"%e5%9c%a8next-jstypescript%e7%9a%84%e7%8e%af%e5%a2%83%e4%b8%ad%e5%bc%95%e5%85%a5emotion%e3%80%82","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8next-jstypescript%e7%9a%84%e7%8e%af%e5%a2%83%e4%b8%ad%e5%bc%95%e5%85%a5emotion%e3%80%82\/","title":{"rendered":"\u5728Next.js+TypeScript\u7684\u73af\u5883\u4e2d\u5f15\u5165Emotion"},"content":{"rendered":"<p>\u4f60\u597d\u3002\u672c\u6b21\u6211\u4eec\u5c06\u5728Next.js\uff0813.4.6 \/ 2023\u5e746\u6708\u6700\u65b0\u7248\uff09+ TypeScript\u7684\u73af\u5883\u4e2d\u4ecb\u7ecd\u4f7f\u7528Emotion\u4f5c\u4e3a\u4e00\u79cdCSS in JS\u7684\u65b9\u6848\u65f6\u7684\u6b65\u9aa4\uff0c\u4f5c\u4e3a\u5907\u5fd8\u5f55\u8bb0\u5f55\u4e0b\u6765\u3002<\/p>\n<h1>\u672c\u6b21\u7684\u73af\u5883<\/h1>\n<p>\u5bfc\u5165\u7684\u5305\u5982\u4e0b\u6240\u793a\u3002<\/p>\n<pre class=\"post-pre\"><code>\u251c\u2500\u2500 @types\/node@20.3.1\r\n\u251c\u2500\u2500 @types\/react-dom@18.2.5\r\n\u251c\u2500\u2500 @types\/react@18.2.12\r\n\u251c\u2500\u2500 eslint-config-next@13.4.6\r\n\u251c\u2500\u2500 eslint@8.43.0\r\n\u251c\u2500\u2500 next@13.4.6\r\n\u251c\u2500\u2500 react-dom@18.2.0\r\n\u251c\u2500\u2500 react@18.2.0\r\n\u2514\u2500\u2500 typescript@5.1.3\r\n<\/code><\/pre>\n<p>\u5b89\u88c5 Emotion \u662f @emotion\/react \u7684 11.11.1 \u7248\u672c\u3002<\/p>\n<h1>\u5b89\u88c5\u60c5\u611f<\/h1>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5@emotion\/react\u3002<\/p>\n<p>\u4ee5\u4e0b\u6307\u4ee4\u53ef\u7528\u4e8e\u5b89\u88c5@emotion\/react\u3002<\/p>\n<pre class=\"post-pre\"><code>npm install --save @emotion\/react\r\n<\/code><\/pre>\n<h1>\u5728tsconfig.json\u4e2d\u6dfb\u52a0jsxImportSource<\/h1>\n<p>\u4ec5\u5b89\u88c5\u65e0\u6cd5\u6b63\u5e38\u8fd0\u884c\u3002\u8bf7\u6309\u4ee5\u4e0b\u793a\u4f8b\uff0c\u5728tsconfig.json\u7684compilerOptions\u4e2d\u6dfb\u52a0jsxImportSource\u9879\u76ee\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"p\">{<\/span>\r\n    <span class=\"s2\">\"compilerOptions\"<\/span> <span class=\"p\">{<\/span>\r\n    <span class=\"err\">...<\/span>\r\n    <span class=\"nl\">\"jsxImportSource\"<\/span><span class=\"p\">:<\/span> <span class=\"s2\">\"@emotion\/react\"<\/span><span class=\"p\">,<\/span>\r\n    <span class=\"err\">...<\/span>\r\n    <span class=\"p\">}<\/span>\r\n<span class=\"p\">}<\/span>\r\n<\/code><\/pre>\n<p>\u8fd9\u6837\uff0c\u5b89\u88c5\u5c31\u5b8c\u6210\u4e86\u3002<\/p>\n<h1>\u8bd5\u7740\u4eb2\u81ea\u4f7f\u7528\u4e00\u4e0b<\/h1>\n<p>\u5982\u524d\u6240\u8ff0\uff0cEmotion\u662f\u4e00\u79cd\u4f7fCSS in JS\u6210\u4e3a\u53ef\u80fd\u7684\u5e93\u3002\u987e\u540d\u601d\u4e49\uff0c\u5b83\u5141\u8bb8\u5c06CSS\u4ee3\u7801\u76f4\u63a5\u5199\u5728JavaScript\uff08\u6216TypeScript\uff09\u6587\u4ef6\u4e2d\u3002<\/p>\n<h2>\u4e4b\u524d<\/h2>\n<p>\u5047\u8bbe\u6709\u4ee5\u4e0b\u7684\u7ec4\u4ef6\uff0c\u5b83\u4ec5\u7528\u4e8e\u663e\u793a\u6587\u672c\u3002\u672c\u6b21\u7684\u76ee\u6807\u662f\u5c06\u6587\u672c\u7684\u989c\u8272\u8bbe\u4e3a\u7ea2\u8272\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"k\">export<\/span> <span class=\"k\">default<\/span> <span class=\"kd\">function<\/span> <span class=\"nf\">Title<\/span><span class=\"p\">(){<\/span>\r\n    <span class=\"k\">return <\/span><span class=\"p\">(<\/span>\r\n        <span class=\"p\">&lt;<\/span><span class=\"nt\">div<\/span><span class=\"p\">&gt;<\/span>\r\n            <span class=\"p\">&lt;<\/span><span class=\"nt\">h1<\/span><span class=\"p\">&gt;<\/span>This is Title<span class=\"p\">&lt;\/<\/span><span class=\"nt\">h1<\/span><span class=\"p\">&gt;<\/span>\r\n        <span class=\"p\">&lt;\/<\/span><span class=\"nt\">div<\/span><span class=\"p\">&gt;<\/span>\r\n    <span class=\"p\">)<\/span>\r\n<span class=\"p\">}<\/span>\r\n<\/code><\/pre>\n<h2>\u5728\u4e4b\u540e<\/h2>\n<p>\u901a\u8fc7\u4f7f\u7528Emotion\u5728JS\u4e2d\u8fdb\u884cCSS\u6837\u5f0f\u5316\uff0c\u4f1a\u5f97\u5230\u4ee5\u4e0b\u7ed3\u679c\u3002\uff08\u4e00\u4f8b\uff09<\/p>\n<pre class=\"post-pre\"><code><span class=\"k\">import<\/span> <span class=\"p\">{<\/span> <span class=\"nx\">css<\/span> <span class=\"p\">}<\/span> <span class=\"k\">from<\/span> <span class=\"dl\">\"<\/span><span class=\"s2\">@emotion\/react<\/span><span class=\"dl\">\"<\/span>\r\n\r\n<span class=\"k\">export<\/span> <span class=\"k\">default<\/span> <span class=\"kd\">function<\/span> <span class=\"nf\">Title<\/span><span class=\"p\">(){<\/span>\r\n    <span class=\"k\">return <\/span><span class=\"p\">(<\/span>\r\n        <span class=\"p\">&lt;<\/span><span class=\"nt\">div<\/span><span class=\"p\">&gt;<\/span>\r\n            <span class=\"p\">&lt;<\/span><span class=\"nt\">h1<\/span> <span class=\"na\">css<\/span><span class=\"p\">=<\/span><span class=\"si\">{<\/span><span class=\"nx\">titleStyle<\/span><span class=\"si\">}<\/span><span class=\"p\">&gt;<\/span>This is Title<span class=\"p\">&lt;\/<\/span><span class=\"nt\">h1<\/span><span class=\"p\">&gt;<\/span>\r\n        <span class=\"p\">&lt;\/<\/span><span class=\"nt\">div<\/span><span class=\"p\">&gt;<\/span>\r\n    <span class=\"p\">)<\/span>\r\n<span class=\"p\">}<\/span>\r\n\r\n<span class=\"kd\">const<\/span> <span class=\"nx\">titleStyle<\/span> <span class=\"o\">=<\/span> <span class=\"nf\">css <\/span><span class=\"p\">({<\/span>\r\n    <span class=\"na\">color<\/span><span class=\"p\">:<\/span> <span class=\"s2\">`red`<\/span><span class=\"p\">,<\/span>\r\n<span class=\"p\">})<\/span>\r\n<\/code><\/pre>\n<h1>\u8bf7\u7ed9\u6211\u63d0\u4f9b\u60a8\u7684\u53c2\u8003\u8d44\u6599\u3002<\/h1>\n<p>&nbsp;<\/p>\n<p>\u4ee5\u4e0a\u662f\u5173\u4e8e\u5728Next.js+TypeScript\u73af\u5883\u4e2d\u5f15\u5165Emotion\u7684\u5185\u5bb9\u3002<br \/>\n\u975e\u5e38\u611f\u8c22\u60a8\u7684\u9605\u8bfb\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f60\u597d\u3002\u672c\u6b21\u6211\u4eec\u5c06\u5728Next.js\uff0813.4.6 \/ 2023\u5e746\u6708\u6700\u65b0\u7248\uff09+ TypeScript\u7684\u73af\u5883\u4e2d\u4ecb\u7ecd [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-38491","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u5728Next.js+TypeScript\u7684\u73af\u5883\u4e2d\u5f15\u5165Emotion - Blog - Silicon Cloud<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/zh\/blog\/\u5728next-jstypescript\u7684\u73af\u5883\u4e2d\u5f15\u5165emotion\u3002\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u5728Next.js+TypeScript\u7684\u73af\u5883\u4e2d\u5f15\u5165Emotion\" \/>\n<meta property=\"og:description\" content=\"\u4f60\u597d\u3002\u672c\u6b21\u6211\u4eec\u5c06\u5728Next.js\uff0813.4.6 \/ 2023\u5e746\u6708\u6700\u65b0\u7248\uff09+ TypeScript\u7684\u73af\u5883\u4e2d\u4ecb\u7ecd [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/zh\/blog\/\u5728next-jstypescript\u7684\u73af\u5883\u4e2d\u5f15\u5165emotion\u3002\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2023-01-25T03:34:54+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-15T01:56:29+00:00\" \/>\n<meta name=\"author\" content=\"\u97f5, \u79d1\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u97f5, \u79d1\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8next-jstypescript%e7%9a%84%e7%8e%af%e5%a2%83%e4%b8%ad%e5%bc%95%e5%85%a5emotion%e3%80%82\/\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8next-jstypescript%e7%9a%84%e7%8e%af%e5%a2%83%e4%b8%ad%e5%bc%95%e5%85%a5emotion%e3%80%82\/\",\"name\":\"\u5728Next.js+TypeScript\u7684\u73af\u5883\u4e2d\u5f15\u5165Emotion - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\"},\"datePublished\":\"2023-01-25T03:34:54+00:00\",\"dateModified\":\"2024-01-15T01:56:29+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/6530331a63adef3b3443a1fab53a0e6e\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8next-jstypescript%e7%9a%84%e7%8e%af%e5%a2%83%e4%b8%ad%e5%bc%95%e5%85%a5emotion%e3%80%82\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8next-jstypescript%e7%9a%84%e7%8e%af%e5%a2%83%e4%b8%ad%e5%bc%95%e5%85%a5emotion%e3%80%82\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8next-jstypescript%e7%9a%84%e7%8e%af%e5%a2%83%e4%b8%ad%e5%bc%95%e5%85%a5emotion%e3%80%82\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/zh\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u5728Next.js+TypeScript\u7684\u73af\u5883\u4e2d\u5f15\u5165Emotion\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/\",\"name\":\"Blog - Silicon Cloud\",\"description\":\"\",\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/6530331a63adef3b3443a1fab53a0e6e\",\"name\":\"\u97f5, \u79d1\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/429ccb39b3fff5188bc17986222cfb0936cbadb8cc933cff04ab5ca01bd30a08?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/429ccb39b3fff5188bc17986222cfb0936cbadb8cc933cff04ab5ca01bd30a08?s=96&d=mm&r=g\",\"caption\":\"\u97f5, \u79d1\"},\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/author\/yunke\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8next-jstypescript%e7%9a%84%e7%8e%af%e5%a2%83%e4%b8%ad%e5%bc%95%e5%85%a5emotion%e3%80%82\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"\u5728Next.js+TypeScript\u7684\u73af\u5883\u4e2d\u5f15\u5165Emotion - Blog - Silicon Cloud","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/zh\/blog\/\u5728next-jstypescript\u7684\u73af\u5883\u4e2d\u5f15\u5165emotion\u3002\/","og_locale":"zh_CN","og_type":"article","og_title":"\u5728Next.js+TypeScript\u7684\u73af\u5883\u4e2d\u5f15\u5165Emotion","og_description":"\u4f60\u597d\u3002\u672c\u6b21\u6211\u4eec\u5c06\u5728Next.js\uff0813.4.6 \/ 2023\u5e746\u6708\u6700\u65b0\u7248\uff09+ TypeScript\u7684\u73af\u5883\u4e2d\u4ecb\u7ecd [&hellip;]","og_url":"https:\/\/www.silicloud.com\/zh\/blog\/\u5728next-jstypescript\u7684\u73af\u5883\u4e2d\u5f15\u5165emotion\u3002\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2023-01-25T03:34:54+00:00","article_modified_time":"2024-01-15T01:56:29+00:00","author":"\u97f5, \u79d1","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u97f5, \u79d1","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8next-jstypescript%e7%9a%84%e7%8e%af%e5%a2%83%e4%b8%ad%e5%bc%95%e5%85%a5emotion%e3%80%82\/","url":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8next-jstypescript%e7%9a%84%e7%8e%af%e5%a2%83%e4%b8%ad%e5%bc%95%e5%85%a5emotion%e3%80%82\/","name":"\u5728Next.js+TypeScript\u7684\u73af\u5883\u4e2d\u5f15\u5165Emotion - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website"},"datePublished":"2023-01-25T03:34:54+00:00","dateModified":"2024-01-15T01:56:29+00:00","author":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/6530331a63adef3b3443a1fab53a0e6e"},"breadcrumb":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8next-jstypescript%e7%9a%84%e7%8e%af%e5%a2%83%e4%b8%ad%e5%bc%95%e5%85%a5emotion%e3%80%82\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8next-jstypescript%e7%9a%84%e7%8e%af%e5%a2%83%e4%b8%ad%e5%bc%95%e5%85%a5emotion%e3%80%82\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8next-jstypescript%e7%9a%84%e7%8e%af%e5%a2%83%e4%b8%ad%e5%bc%95%e5%85%a5emotion%e3%80%82\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/zh\/blog\/"},{"@type":"ListItem","position":2,"name":"\u5728Next.js+TypeScript\u7684\u73af\u5883\u4e2d\u5f15\u5165Emotion"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website","url":"https:\/\/www.silicloud.com\/zh\/blog\/","name":"Blog - Silicon Cloud","description":"","inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/6530331a63adef3b3443a1fab53a0e6e","name":"\u97f5, \u79d1","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/429ccb39b3fff5188bc17986222cfb0936cbadb8cc933cff04ab5ca01bd30a08?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/429ccb39b3fff5188bc17986222cfb0936cbadb8cc933cff04ab5ca01bd30a08?s=96&d=mm&r=g","caption":"\u97f5, \u79d1"},"url":"https:\/\/www.silicloud.com\/zh\/blog\/author\/yunke\/"},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8next-jstypescript%e7%9a%84%e7%8e%af%e5%a2%83%e4%b8%ad%e5%bc%95%e5%85%a5emotion%e3%80%82\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/38491","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/comments?post=38491"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/38491\/revisions"}],"predecessor-version":[{"id":58408,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/38491\/revisions\/58408"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/media?parent=38491"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/categories?post=38491"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/tags?post=38491"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}