Before we begin, we need to complete some simple environment configurations:
Install Trae: Visit the Trae official website to download the version for your operating system. It supports Windows, Mac, and Linux platforms.
Prepare a project that needs coding: Set up a demo blank project for this example.
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.
Step 2: Give Instructions
You can issue instructions to the AI tool following this structure for the most accurate understanding of your needs:
Instruction Template
PleasehelpmewiththeimageIuploaded:
1. **GenerateReactcomponentcode** -Createanewpagecomponent-Componentfilepath: src/pages/[folder named based on image content]/index.tsx-UseTypeScript-Includenecessarystylefiles2. **Automaticallyregisterroutes** -Intheexistingroutingconfiguration (usually src/router/index.tsx or similar files) -Addroutingconfigurationforthenewpage-Routepath: /[suggested route path based on image content]3. **Folderstructure** -Createacompletefolderstructure-Includecomponentfiles, stylefiles (if needed) -ExportconfigurationImagecontentdescription: [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.Createall components needed for the elements in the image, automatically split them, andcreate 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.
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!
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)
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
Summary
Although there are some differences from the original image, all interface elements have been captured. To achieve better results, here are some solutions:
You can install the Figma plugin provided in the plugin marketplace!
Use better large models with image recognition and code generation capabilities