跳到主要内容
极客日志极客日志面向AI+效率的开发者社区
首页博客GitHub 精选镜像AI 生图工具UI配色美学隐私政策关于联系
搜索内容 / 工具 / 仓库 / 镜像...⌘K搜索
注册
博客列表
JavaScriptAI大前端

Trae AI 将设计稿自动生成前端代码图文指南

如何使用 Trae AI 工具将设计稿自动生成前端代码。主要步骤包括:安装 Trae 并切换至 Builder 模式,上传设计图,通过指令模板指定技术栈(如 React/Vue/TypeScript)及路由配置,授权 AI 解析并生成代码,最后进行实时预览与调整。文章提供了详细的指令示例和补充信息建议,支持多语言输出及版本控制回滚,旨在提升前端开发效率。

古灵精怪发布于 2026/4/6更新于 2026/7/1855 浏览
Trae AI 将设计稿自动生成前端代码图文指南
Trae AI 将设计稿自动生成前端代码

准备工作:

在开始之前,我们需要完成一些简单的环境配置:

  1. 安装 Trae:访问 Trae 官网下载对应操作系统的版本,支持 Windows、Mac 和 Linux 全平台。
  2. 准备一个需要写代码的项目:创建一个空白项目用于演示。
  3. 选择工作模式:启动 Trae 后,切换到 Builder 模式,该模式可以自动帮你写代码。

实操

第 1 步:上传设计图

在 Trae 的 Builder 模式下,直接拖拽或上传你的设计图文件。Trae 支持多种格式设计稿。

选择一个设计图作为示例。

image

第 2 步:下达指令

你可以按照以下结构向 AI 工具下达指令,这样它能最准确地理解你的需求:

image

指令模板
请根据我上传的图片,帮我:
1. **生成 React 组件代码** - 创建一个新的页面组件 - 组件文件路径:src/pages/[根据图片内容命名的文件夹]/index.tsx - 使用 TypeScript - 包含必要的样式文件
2. **自动注册路由** - 在现有的路由配置中(通常是 src/router/index.tsx 或类似文件) - 添加新页面的路由配置 - 路由路径:/[根据图片内容建议的路由路径]
3. **文件夹结构** - 创建完整的文件夹结构 - 包含组件文件、样式文件(如需要) - 导出配置
图片内容描述:【这里简单描述图片显示的页面功能,比如:用户管理界面、仪表盘、登录页面等】
具体示例
请根据我上传的图片,帮我:
1. 在 app 文件夹下创建 demo1016 文件夹,生成 React 组件
2. 创建图片中所需要的元素的所有组件,请自动拆分,可以创建多个子组件
3. 自动注册路由,路径为 "/demo1016"
4. 组件要包含页面中所有元素
补充信息(让 AI 更准确)

如果可能,还可以提供:

  • 项目技术栈:使用的是 React Router v6 还是其他路由库?
  • UI 组件库:Ant Design、Material-UI 还是自定义组件?
  • 状态管理:Redux、Zustand 还是 Context?
  • 样式方案:CSS Modules、Styled-components 还是 Tailwind?

这样 AI 工具就能生成完全符合你项目结构的代码,并正确集成到现有项目中。

第 3 步:AI 自动解析

上传后,Trae 会启动其 AI 引擎自动分析设计稿。

image

image

授权 AI 自动执行命令,创建编写代码

建议使用 Git 记录代码改动。AI 工具生成的代码可以点击撤回,如果多次对话最终结果仍旧不满意,可以使用分支记录随时撤回。

image

第 4 步:AI 自动生成高质量代码

解析完成后,Trae 会自动生成对应的前端代码。你可以根据项目需求选择输出的技术栈:

  • React 组件(支持 TypeScript)
  • Vue 组件(支持 Vue 2 和 Vue 3)
  • 原生 HTML/CSS/JavaScript
  • iOS 原生 UI 代码(Swift)

image

第 5 步:实时预览与调整

生成代码后,如果发现与设计稿有差异,可以通过自然语言指示 AI 进行调整:

  • '将按钮颜色改为蓝色'
  • '增加元素之间的间距'
  • '添加悬停动效'

image

image

image

image

总结

虽然和原图有一些差异,但是界面元素已经全部捕获到了。想要获得更好的效果,有下面几种方案:

  1. 可以安装插件市场提供的 Figma 插件。
  2. 使用更好的具有图片识别能力与代码生成能力的大模型。

image


Preparation:

Before we begin, we need to complete some simple environment configurations:

  1. Install Trae: Visit the Trae official website to download the version for your operating system. It supports Windows, Mac, and Linux platforms.
  2. Prepare a project that needs coding: Set up a demo blank project for this example.
  3. Select working mode: After launching Trae, switch to Builder mode, which can automatically write code for you!

Practical Steps

Step 1: Upload Design Mockup

In Trae's Builder mode, directly drag and drop or upload your design mockup file. Trae supports multiple formats of design drafts.

Select a design image as an example.

image

Step 2: Give Instructions

You can issue instructions to the AI tool following this structure for the most accurate understanding of your needs:

image

Instruction Template
Please help me with the image I uploaded:
1. **Generate React component code** - Create a new page component - Component file path: src/pages/[folder named based on image content]/index.tsx - Use TypeScript - Include necessary style files
2. **Automatically register routes** - In the existing routing configuration (usually src/router/index.tsx or similar files) - Add routing configuration for the new page - Route path: /[suggested route path based on image content]
3. **Folder structure** - Create a complete folder structure - Include component files, style files (if needed) - Export configuration
Image content description: [Briefly describe the page function shown in the image, such as: user management interface, dashboard, login page, etc.]
Specific Example
Please help me with the image I uploaded:
1. Create a demo1016 folder under the app folder and generate React components
2. Create all components needed for the elements in the image, automatically split them, and create multiple sub-components
3. Automatically register the route with path "/demo1016"
4. Components should include all elements in the page
Additional Information (For More Accurate AI)

If possible, you can also provide:

  • Project tech stack: Are you using React Router v6 or another routing library?
  • UI component library: Ant Design, Material-UI, or custom components?
  • State management: Redux, Zustand, or Context?
  • Styling solution: CSS Modules, Styled-components, or Tailwind?

This way, the AI tool can generate code that perfectly matches your project structure and integrates correctly into your existing project.

Step 3: AI Automatic Analysis

After uploading, Trae will start its AI engine to automatically analyze the design draft.

image

image

Authorize AI to Automatically Execute Commands and Write Code

Use Git to track code changes. The code generated by AI tools can be rolled back with a click. If you're still not satisfied with the final result after multiple conversations, you can always roll back using branch records!

image

Step 4: AI Automatically Generates High-Quality Code

After analysis, Trae will automatically generate the corresponding frontend code. You can choose the output tech stack according to your project needs:

  • React components (supporting TypeScript)
  • Vue components (supporting Vue 2 and Vue 3)
  • Native HTML/CSS/JavaScript
  • iOS native UI code (Swift)

image

Step 5: Real-time Preview and Adjustment

After generating the code, if you find any differences from the design draft, you can instruct the AI to make adjustments using natural language:

  • Change the button color to blue
  • Increase the spacing between elements
  • Add hover animations

image

image

image

image

Summary

Although there are some differences from the original image, all interface elements have been captured. To achieve better results, here are some solutions:

  1. You can install the Figma plugin provided in the plugin marketplace!
  2. Use better large models with image recognition and code generation capabilities

image

目录

  1. Trae AI 将设计稿自动生成前端代码
  2. 准备工作:
  3. 实操
  4. 第 1 步:上传设计图
  5. 第 2 步:下达指令
  6. 指令模板
  7. 具体示例
  8. 补充信息(让 AI 更准确)
  9. 第 3 步:AI 自动解析
  10. 授权 AI 自动执行命令,创建编写代码
  11. 第 4 步:AI 自动生成高质量代码
  12. 第 5 步:实时预览与调整
  13. 总结
  14. Preparation:
  15. Practical Steps
  16. Step 1: Upload Design Mockup
  17. Step 2: Give Instructions
  18. Instruction Template
  19. Specific Example
  20. Additional Information (For More Accurate AI)
  21. Step 3: AI Automatic Analysis
  22. Authorize AI to Automatically Execute Commands and Write Code
  23. Step 4: AI Automatically Generates High-Quality Code
  24. Step 5: Real-time Preview and Adjustment
  25. Summary
  • 免费图片AI生成工具免费生成了解详情
  • Magick API 一键接入全球大模型注册送1000万token查看
  • 免费图片视频在线生成30秒,将你的创意变成现实开始设计
  • X/Twitter免费视频下载器免登陆无限额度免费视频解析下载了解详情
  • 100+免费在线小游戏爽一把
极客日志微信公众号二维码

微信扫一扫,关注极客日志

微信公众号「极客日志V2」,在微信中扫描左侧二维码关注。展示文案:极客日志V2 zeeklog

更多推荐文章

查看全部
  • Linux 下 Git 入门:高效管理代码库实战指南
  • Java 编译报错 No interface expected here 的排查与修复
  • Linux 系统编译安装 GPU 版 LAMMPS 指南
  • 人形机器人:从万物可机器人化到终极通用平台的百万亿赛道逻辑
  • Spring Boot 启动引导类:命名约定与底层启动原理
  • Poe 平台:Quora 推出的 AI 模型整合工具
  • Python 数据清洗实战:缺失值、异常值与格式处理
  • 鸿蒙系统 PC 版安装与使用指南
  • GESP C++ 一级考试全流程及编程题核心模板
  • WSL2 环境下 Git 与 Gitee 代码管理实战
  • Android 应用视觉优化:10 个 UI 技巧
  • MySQL 核心原理与实战进阶指南
  • Qwen1.5-0.5B-Chat 轻量模型本地部署与 WebUI 实战
  • 使用 Dexie 操作前端 IndexedDB 数据库教程
  • AR/VR 展项与实体展陈融合施工工艺及交互校准技术
  • 主流大模型介绍(GPT、Llama、ChatGLM、Qwen、deepseek)
  • 单链表应用:经典算法题与通讯录实现
  • GitHub 代码文件抓取与数据可视化实践(Python 实现)
  • 基于 SpringBoot 的协同过滤电影推荐系统
  • OpenClaw 对接飞书机器人配置问题排查:消息不回复与 Gateway 断开

相关免费在线工具

  • RSA密钥对生成器

    生成新的随机RSA私钥和公钥pem证书。 在线工具,RSA密钥对生成器在线工具,online

  • Mermaid 预览与可视化编辑

    基于 Mermaid.js 实时预览流程图、时序图等图表,支持源码编辑与即时渲染。 在线工具,Mermaid 预览与可视化编辑在线工具,online

  • 随机西班牙地址生成器

    随机生成西班牙地址(支持马德里、加泰罗尼亚、安达卢西亚、瓦伦西亚筛选),支持数量快捷选择、显示全部与下载。 在线工具,随机西班牙地址生成器在线工具,online

  • Keycode 信息

    查找任何按下的键的javascript键代码、代码、位置和修饰符。 在线工具,Keycode 信息在线工具,online

  • Escape 与 Native 编解码

    JavaScript 字符串转义/反转义;Java 风格 \uXXXX(Native2Ascii)编码与解码。 在线工具,Escape 与 Native 编解码在线工具,online

  • JavaScript / HTML 格式化

    使用 Prettier 在浏览器内格式化 JavaScript 或 HTML 片段。 在线工具,JavaScript / HTML 格式化在线工具,online