1分钟,图文并茂手把手教你用Trae AI将你的设计稿自动生成前端代码 One-Minute Guide with Visuals: Turn Design Mockups into Code wit

1分钟,图文并茂手把手教你用Trae AI将你的设计稿自动生成前端代码 One-Minute Guide with Visuals: Turn Design Mockups into Code wit

1分钟,图文并茂手把手教你用Trae AI将你的设计稿自动生成前端代码 One-Minute Guide with Visuals: Turn Design Mockups into Code with Trae AI

无需手动编码,设计图直接变代码,AI正在重塑前端开发的工作流。| No manual coding needed. Design mockups directly transform into code. AI is reshaping frontend development workflows.

本文为中英文双语,需要英文博客可以滑动到下面查看哦 | This is a bilingual article. Scroll down for the English version.

准备工作:

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

  1. 安装Trae:访问Trae官网(trae.ai或trae.cn)下载对应操作系统的版本,支持Windows、Mac和Linux全平台。
  2. 准备一个需要写代码的项目:我搞了一个demo空白项目来进行举例~
  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插件哦~

使用更好的具有图片识别能力与代码生成能力的大模型

image

Preparation:

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

  1. Install Trae: Visit the Trae official website (trae.ai or trae.cn) to download the version for your operating system. It supports Windows, Mac, and Linux platforms.
  2. Prepare a project that needs coding: I’ve 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.

We’ll randomly find an image from Baidu as a case study. Let’s stop hesitating and use Baidu as our 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

If you’re unsure, we can generally 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. Moreover, I used a casually-screenshot image & free model, not a real design draft. 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
Conclusion | 结语
  • That’s all for today~ - | 今天就写到这里啦~
  • Guys, ( ̄ω ̄( ̄ω ̄〃 ( ̄ω ̄〃)ゝ See you tomorrow~ | 小伙伴们,( ̄ω ̄( ̄ω ̄〃 ( ̄ω ̄〃)ゝ我们明天再见啦~~
  • Everyone, be happy every day! 大家要天天开心哦
  • Welcome everyone to point out any mistakes in the article~ | 欢迎大家指出文章需要改正之处~
  • Learning has no end; win-win cooperation | 学无止境,合作共赢
  • Welcome all the passers-by, boys and girls, to offer better suggestions! ~ | 欢迎路过的小哥哥小姐姐们提出更好的意见哇~~

Read more

Telegram bot & Mini-App开发实践---Telegram简单介绍与初始化小程序获取window.Telegram.WebApp对象并解析

Telegram bot & Mini-App开发实践---Telegram简单介绍与初始化小程序获取window.Telegram.WebApp对象并解析

➡️【好看的灵魂千篇一律,有趣的鲲志一百六七!】- 欢迎认识我~~作者:鲲志说(公众号、B站同名,视频号:鲲志说996)科技博主:极星会 星辉大使后端研发:java、go、python、TS,前电商、现web3主理人:COC杭州开发者社区主理人 、周周黑客松杭州主理人、AI爱好者: AI电影共创社杭州核心成员、阿里蚂蚁校友会技术AI分会副秘书长博客专家:阿里云专家博主;ZEEKLOG博客专家、后端领域新星创作者、内容合伙人 今天是2024年10月24日,又是一年1024程序员节。和往常一样,平淡的度过了一天,又和往常不一样,收到了人生第一束花花🌹值得纪念。就像两年前毅然决然的从电商行业进入一个零基础零认知的web3世界一样,都有第一次的刻骨铭心,选择了就勇敢的做下去,开花结果是期待,但过程也十分重要。也像2016年下半年第一次注册ZEEKLOG去检索问题的解决方案,经过多番查阅实践,终于解决;更像2017年9月27日我的第一篇ZEEKLOG博客文章潦草问世,当初不追求得到什么,只把ZEEKLOG文章当作是学习笔记,知识总结,一路写写停停,不知不觉间也悄然过去了7个年头,断然想不到博

30天CTF入门:Web+Misc速成计划

30 天网络安全入门学习计划(Web+Misc 方向,适配 CTF 刷题) 适配零基础入门,全程围绕 Burp Suite 实操 + CTF 基础刷题,聚焦 Web 安全(核心)+ 杂项(Misc)入门,使用平台为CTFHub(主打)+Bugku CTF(辅)+ 攻防世界(进阶),每天任务控制在1.5-2 小时,分基础打牢(1-10 天)、漏洞进阶 + Misc 入门(11-20 天)、综合刷题 + 能力提升(21-30 天) 三个阶段,核心任务必做、拓展任务可选,贴合学生党时间安排。 通用要求 1.

如何快速实现前端Word文档生成:DOCX.js完整使用手册

在现代Web开发中,前端直接生成Word文档已成为提升用户体验的关键技术。DOCX.js作为一款纯JavaScript实现的客户端DOCX生成库,让开发者无需后端支持就能创建专业的Microsoft Word文档。本文将为你全面解析这个强大工具的使用方法,从基础配置到高级功能,助你快速掌握前端文档生成的核心技能。 【免费下载链接】DOCX.jsGenerate Microsoft Word DOCX files in pure client-side JavaScript. Try in Chrome 项目地址: https://gitcode.com/gh_mirrors/do/DOCX.js 🎯 快速上手:5分钟创建你的第一个Word文档 想要立即体验DOCX.js的强大功能?只需三个简单步骤: 1. 引入核心依赖文件 - 在你的HTML页面中添加以下脚本引用: <script src="libs/base64.js">

Vue与C++:前端与系统开发的差异

好的,我们来分析一下Vue和C++的区别: 1. 用途与领域 * Vue:是一个用于构建用户界面的渐进式 JavaScript 框架。它主要用于开发Web前端的单页面应用。核心是帮助开发者高效地构建和维护复杂的、交互式的网页界面,处理视图层和数据绑定。 * C++:是一种通用的、编译型的编程语言。它几乎可以用于开发任何类型的软件,包括操作系统、游戏引擎、桌面应用、高性能服务器后端、嵌入式系统、科学计算等。它更接近硬件,提供对系统资源的底层控制。 2. 语法与特性 * Vue: * 基于HTML模板或JSX(类似HTML的语法扩展)来声明式地描述UI。 * 核心特性包括响应式数据绑定(数据变化自动更新视图)、组件系统(将UI拆分为独立可复用的单元)、指令(如v-if, v-for等,用于操作DOM)。 * 语法相对简单直观,易于上手,侧重于声明式地描述“界面应该是什么样子”。 * C++: * 语法复杂,需要显式声明变量类型(强类型语言),支持面向对象编程(类、继承、