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

AI入门系列:AI新手必看:人工智能发展历程与现状分析

AI入门系列:AI新手必看:人工智能发展历程与现状分析

写在前面:为什么AI发展历史很重要? 记得刚开始学习AI的时候,我总觉得历史这种东西很枯燥,不如直接学习最新的技术来得实在。但后来我发现,了解AI的发展历程,就像了解一个人的成长经历一样,能帮助我们更好地理解现在的AI是如何走到今天的,也能帮助我们预测未来可能的发展方向。 有一次,我和一位从事AI研究多年的教授聊天,他告诉我:"现在的学生总想直接学习深度学习,但如果不了解符号主义AI的兴衰,就无法理解为什么深度学习会成功,也无法预见它可能面临的挑战。"这句话让我深受启发。 所以,在这篇文章中,我想和大家一起回顾一下AI的发展历程,不是为了考试背诵那些枯燥的年代和事件,而是为了让我们能够站在历史的高度,更好地理解现在的AI技术,以及它在我们生活中的应用。 人工智能的诞生:一个充满想象力的开始 说起AI的诞生,我们不得不提到1956年的达特茅斯会议。这次会议被公认为人工智能学科的诞生标志。 想象一下那个场景:一群来自不同领域的顶尖科学家,包括约翰·麦卡锡、马文·明斯基、克劳德·香农等,聚集在一起,讨论着一个看似疯狂的问题:"机器能思考吗?"他们相信,只要给机器输入足够多的规则

技术拆解:P2P组网如何一键远程AI

技术拆解:P2P组网如何一键远程AI

文章目录 * **远程访问AI服务的核心是什么?** * **从暴露服务到连接设备** * **核心组件与交互解析** * **安全架构深度剖析** * **一键安装脚本的技术实现** * **# Windows** * **#macOS** * **#Linux** * **与AI工作流的结合实践** 远程访问AI服务的核心是什么? 你自己在电脑或者服务器上装了AI服务,比如大语言模型、Stable Diffusion这些,但是有个头疼的事儿:外面的人或者你在别的地方,怎么既安全又方便地连上这些本地的服务?以前的办法要么得有公网IP,还得敲一堆命令行用SSH隧道,要么就是直接开端口映射,等于把服务直接晾在公网上,太不安全了。 今天咱们就好好说说一种靠P2P虚拟组网的办法,还拿个叫节点小宝的工具举例子,看看它怎么做到不用改啥东西,点一下就装好,还能建个加密的通道,实现那种“服务藏得好好的,想连就能直接连上”的安全远程访问方式。 从暴露服务到连接设备 核心思路转变在于:不再尝试将内网服务端口暴露到公网(一个危险的攻击面),而是将外部访问设

人工智能:自然语言处理在教育领域的应用与实战

人工智能:自然语言处理在教育领域的应用与实战

人工智能:自然语言处理在教育领域的应用与实战 学习目标 💡 理解自然语言处理(NLP)在教育领域的应用场景和重要性 💡 掌握教育领域NLP应用的核心技术(如智能问答、作业批改、个性化学习) 💡 学会使用前沿模型(如BERT、GPT-3)进行教育文本分析 💡 理解教育领域的特殊挑战(如多学科知识、学生认知差异、数据隐私) 💡 通过实战项目,开发一个智能问答系统应用 重点内容 * 教育领域NLP应用的主要场景 * 核心技术(智能问答、作业批改、个性化学习) * 前沿模型(BERT、GPT-3)在教育领域的使用 * 教育领域的特殊挑战 * 实战项目:智能问答系统应用开发 一、教育领域NLP应用的主要场景 1.1 智能问答 1.1.1 智能问答的基本概念 智能问答是通过自然语言与用户进行交互,回答用户问题的程序。在教育领域,智能问答的主要应用场景包括: * 课程问答:回答课程相关的问题(如“什么是机器学习”

AI时代人人都是产品经理:落地流程:AI 核心功能,从需求到上线的全流程管控方法

AI时代人人都是产品经理:落地流程:AI 核心功能,从需求到上线的全流程管控方法

AI的普及正在重构产品经理的工作模式——不再依赖传统的跨部门协作瓶颈,AI可以成为产品经理的"全职助手",覆盖需求分析、原型设计、开发协同、测试验证全流程。本文将拆解AI时代产品核心功能从0到1落地的完整管控方法,让你用AI能力提升300%的落地效率。 一、需求阶段:AI辅助的需求挖掘与标准化 需求是产品的起点,AI可以帮你从海量信息中精准定位用户真实需求,避免"伪需求"浪费资源。 1. 需求挖掘:AI辅助用户洞察 传统需求调研依赖问卷、访谈,效率低且样本有限。AI可以通过以下方式快速完成用户洞察: * 结构化处理非结构化数据:用AI分析用户在社交媒体、客服对话、应用评论中的碎片化反馈,自动提炼高频需求点 * 需求优先级排序:基于KANO模型,AI可以自动将需求划分为基础型、期望型、兴奋型、无差异型四类,输出优先级列表 实战工具与示例: 使用GPT-4+Python脚本批量处理应用商店评论: import openai import pandas as