Code Monkey home page Code Monkey logo

vue-react's Introduction

vue-react

vue-react is a plugin for Vue.js that allows you to use React components just like if they were Vue components.

View Demo

Installation

npm

npm install vue-react --save

If you dont have already, install react and react-dom packages. Install the babel plugin also.

npm install react react-dom babel-plugin-transform-react-jsx --save

Add the plugin in your .babelrc file:

{
    "plugins": ["transform-react-jsx"]
}

Usage

First of all, import and install the plugin:

import VueReact from 'vue-react';

Vue.use(VueReact);

After that, import and register your React components using the new react method:

import { Button } from 'antd';
Vue.react('Button', Button);

Use your registered component inside your App as usual Vue component.

<Button type="danger" size="large" :height="120" @click="buttonClicked">I am a React Button</Button>

How it works ?

The react method creates a new Vue component that maps props and events to the React component. Once mounted, the vue component creates and renders the React component.

This way the registered component works exactly as a Vue component.

Further improvements

  • Support for slots.

vue-react's People

Contributors

alkin avatar wakeupsu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.