惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 司徒正美
The GitHub Blog
The GitHub Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Apple Machine Learning Research
Apple Machine Learning Research
L
LangChain Blog
GbyAI
GbyAI
博客园_首页
V
Visual Studio Blog
Martin Fowler
Martin Fowler
WordPress大学
WordPress大学
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园 - 叶小钗
腾讯CDC
博客园 - Franky
IT之家
IT之家
Google DeepMind News
Google DeepMind News
Microsoft Azure Blog
Microsoft Azure Blog
D
Docker
大猫的无限游戏
大猫的无限游戏
Recent Announcements
Recent Announcements
小众软件
小众软件
博客园 - 三生石上(FineUI控件)
B
Blog
酷 壳 – CoolShell
酷 壳 – CoolShell

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
How does VuReact implement Vue v-on in React
Ryan John · 2026-05-27 · via DEV Community

Ryan John

VuReact is a compiler toolchain for migrating from Vue to React — and for writing React with Vue 3 syntax. In this article, we dive straight into the core: how Vue's common v-on/@ directive is compiled into React code by VuReact.

Before We Start

To keep the examples easy to read, this article follows two simple conventions:

  1. All Vue and React snippets focus on core logic only, with full component wrappers and unrelated configuration omitted.
  2. The discussion assumes you are already familiar with Vue 3's v-on directive usage.

Compilation Mapping

v-on / @: Basic event binding

v-on (shorthand @) is Vue's directive for binding event listeners to respond to user interactions.

  • Vue
<button @click="increment">+1</button>

Enter fullscreen mode Exit fullscreen mode

  • Compiled React
<button onClick={increment}>+1</button>

Enter fullscreen mode Exit fullscreen mode

As the example shows, Vue's @click directive is compiled into React's onClick attribute. VuReact adopts an event attribute compilation strategy, converting template directives into React's standard event attributes. This fully preserves Vue's event binding semantics — when the button is clicked, the increment function is called.

The key characteristics of this compilation approach are:

  1. Semantic consistency: Fully simulates Vue v-on behavior by implementing event listening functionality
  2. Naming conversion: Vue's @click is converted to React's onClick (camelCase naming)
  3. Function passing: Directly passes function references, preserving event handling logic
  4. React-native support: Uses React's standard event system with no additional adaptation required

With event modifiers: Advanced event handling

Vue's event system supports a rich set of modifiers for controlling event behavior. VuReact handles these modifiers through runtime helper functions.

  • Vue
<button @click.stop.prevent="submit">Submit</button>

Enter fullscreen mode Exit fullscreen mode

  • Compiled React
import { dir } from '@vureact/runtime-core';

<button onClick={dir.on('click.stop.prevent', submit)}>Submit</button>

Enter fullscreen mode Exit fullscreen mode

As the example shows, Vue events with modifiers are compiled using the dir.on() helper function. VuReact adopts a modifier runtime processing strategy, converting complex modifier combinations into runtime function calls. This fully preserves Vue's event modifier semantics.

Compilation strategy details:

// Vue: @click.stop.prevent="handler"
// React: onClick={dir.on('click.stop.prevent', handler)}

// Vue: @keyup.enter="search"
// React: onKeyUp={dir.on('keyup.enter', search)}

// Vue: @click.capture="captureHandler"
// React: onClickCapture={dir.on('click.capture', captureHandler)}

Enter fullscreen mode Exit fullscreen mode

How the runtime helper dir.on() works:

  1. Parse modifiers: Parses the event name and modifier string
  2. Create wrapper function: Creates an event handling wrapper function based on the modifiers
  3. Apply modifier logic: Implements the behavior corresponding to each modifier in the wrapper function
  4. Call original handler: Finally calls the developer-provided event handling function

Inline event handling and parameter passing

Vue supports writing inline event handling logic directly in templates, and VuReact handles this correctly as well.

  • Vue
<button @click="count++">Increment</button>
<button @click="sayHello('world')">Say Hello</button>
<button @click="handleEvent($event, 'custom')">With Event Object</button>

Enter fullscreen mode Exit fullscreen mode

  • Compiled React
<button onClick={() => count.value++}>Increment</button>
<button onClick={() => sayHello('world')}>Say Hello</button>
<button onClick={(event) => handleEvent(event, 'custom')}>With Event Object</button>

Enter fullscreen mode Exit fullscreen mode

Compilation strategy:

  1. Expression conversion: Converts Vue template expressions into JSX arrow functions
  2. Event object handling: Vue's $event is converted to React's event parameter
  3. Parameter passing: Preserves the argument order and values of function calls
  4. Reactive updates: Automatically handles .value access (for ref/computed variables, etc.)

defineEmits events and component communication

For component custom events, VuReact also has a corresponding compilation strategy.

  • Vue
<!-- Parent component -->
<Child @custom-event="handleCustom" />

<!-- Child component Child.vue -->
<template>
  <button @click="emits('custom-event', data)">Trigger Event</button>
</template>

<script setup>
const emits = defineEmits(['custom-event']);
</script>

Enter fullscreen mode Exit fullscreen mode

  • Compiled React
// Parent component usage
<Child onCustomEvent={handleCustom} />;

// Child component Child.jsx
function Child(props) {
  return <button onClick={() => props.onCustomEvent?.(data)}>Trigger Event</button>;
}

Enter fullscreen mode Exit fullscreen mode

Compilation rules:

  1. Event name conversion: kebab-case is converted to camelCase (custom-eventonCustomEvent)
  2. emit call conversion: emits() is converted to props callback invocations
  3. Optional chaining guard: Adds ?. optional chaining operator to prevent undefined errors
  4. Type safety: Preserves TypeScript type definition consistency

Compilation strategy summary

VuReact's event compilation strategy demonstrates a complete event system conversion capability:

  1. Basic event mapping: Precisely maps Vue event directives to React event attributes
  2. Modifier support: Fully supports Vue event modifiers through runtime helper functions
  3. Inline handling: Correctly handles inline event expressions in templates
  4. Custom events: Supports custom event communication between components
  5. Type safety: Preserves TypeScript type definition integrity

VuReact's compilation strategy ensures a smooth migration from Vue to React. Developers do not need to manually rewrite event handling logic. The compiled code preserves Vue's semantics and functionality while following React's event handling best practices, keeping the migrated application fully interactive.

Related Links