• Stars
    star
    431
  • Rank 100,866 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 6 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿ› ๏ธ ๐Ÿ‘‰ Try to transform Vue component to React component

npm-version license js-standard-style

vue-to-react

๐Ÿ› ๏ธ ๐Ÿ‘‰ Try to transform Vue component(support JSX and SFC) to React component.

Since v0.0.8 support SFC

Preview screenshots

Transform JSX Component:

jsx

Transform SFC Component:

sfc

Install

Prerequisites: Node.js (>=8.0) and NPM (>=5.0)

$ npm install vue-to-react -g

Usage

Usage: vtr [options]

Options:

  -V, --version     output the version number
  -i, --input       the input path for vue component
  -o, --output      the output path for react component, which default value is process.cwd()
  -n, --name        the output file name, which default value is "react.js"
  -h, --help        output usage information

Examples:

$ vtr -i my/vue/component

The above code will transform my/vue/component.js to ${process.cwd()}/react.js.

$ vtr -i my/vue/component -o my/vue -n test

The above code will transform my/vue/component.js to my/vue/test.js.

Here is a demo.

Attention

The following list you should be pay attention when you are using vue-to-react to transform a vue component to react component:

// Not support 
<div v-bind:class="{ active: isActive }"></div>
<div v-bind:class="[activeClass, errorClass]"></div>

// support
<div v-bind:class="classes"></div>
computed: {
    classes () {
        // ...
        return your-classes;
    }
}

// ...

// react component
// ...

render () {
    const classes = your-classes;
    return (
        <div class={classes}></div> 
    )
}
// Not support 
<div v-bind:style="{ color: activeColor, fontSize: fontSize + 'px' }"></div>
<div v-bind:style="[baseStyles, overridingStyles]"></div>

// support
<div v-bind:style="style"></div>
computed: {
    style () {
        return {
            activeColor: 'red',
            fontSize: 30
        }
    }
}

// ...

// react component
// ...

render () {
    const style = {
      activeColor: 'red',
      fontSize: 30
    };
    return (
        <div style={style}></div> 
    )
}
  • Not support watch prop of vue component
  • Not support components prop of vue component if you are transforming a JSX component. See component tip. But support components prop when you are transforming SFC.
  • Only supports partial built-in Vue directives(SFC): v-if, v-else, v-show, v-for, v-bind, v-on, v-text and v-html.
  • Not support v-bind shorthand and v-on shorthand(SFC):
// Not support
<div :msg="msg" @click="clickHandler"></div>

// Support
<div v-bind:msg="msg" v-on:click="clickHandler"></div>
  • Not support custom directives and filter expression(SFC).
  • Only supports partial lift-cycle methods of vue component. Lift-cycle relations mapping as follows:
// Life-cycle methods relations mapping
const cycle = {
    'created': 'componentWillMount',
    'mounted': 'componentDidMount',
    'updated': 'componentDidUpdate',
    'beforeDestroy': 'componentWillUnmount',
    'errorCaptured': 'componentDidCatch',
    'render': 'render'
};
  • Each computed prop should be a function:
// ...

computed: {
    // support
    test () {
        return your-computed-value;
    },

    // not support
    test2: {
        get () {},
        set () {}
    }
}

// ...
  • Computed prop of vue component will be put into the render method of react component:
// vue component
// ...

computed: {
    // support
    test () {
        this.title = 'messages'; // Don't do this, it won't be handle and you will receive a warning.
        return this.title + this.msg;
    }
}

// ...

// react component
// ...

render () {
    const test = this.state.title + this.state.msg;
}

// ...

Development

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

LICENSE

This repo is released under the MIT.

More Repositories

1

blog

๐Ÿถ ๐Ÿ‘ ๐ŸŒŸ Welcome to star
JavaScript
3,782
star
2

front-end-handbook

Front-end Developer HandBook. Read online: https://dwqs.gitbooks.io/frontenddevhandbook/content/
CSS
605
star
3

area-data

ไธญๅ›ฝ็œๅธ‚ๅŒบๆ•ฐๆฎ(ๅซๆธฏๆพณๅฐ)
JavaScript
482
star
4

vue-area-linkage

็œๅธ‚ๅŒบ่”ๅŠจ้€‰ๆ‹ฉ: https://dwqs.github.io/vue-area-linkage/
Vue
477
star
5

area-puppeteer

ๅŸบไบŽ puppeteer ็š„ไธญๅ›ฝ่กŒๆ”ฟๅŒบๅŸŸๆŠ“ๅ–็ˆฌ่™ซ
JavaScript
169
star
6

react-style-guide

A mostly reasonable approach to React and JSX
157
star
7

vue-mobx

๐Ÿ˜„ โญ ๐Ÿ˜‡ Mobx binding for Vuejs 2.
TypeScript
110
star
8

v2-table

A simple table component based Vue 2.x: https://dwqs.github.io/v2-table/
Vue
100
star
9

js2excel

๐Ÿ˜Œ ๐Ÿ˜ƒ ๐Ÿ‘ฟ A simple module for excel and json converts each other, which works in the browser.
TypeScript
99
star
10

v2-datepicker

A simple datepicker component based Vue 2.x: https://dwqs.github.io/v2-datepicker/
JavaScript
90
star
11

tech-read

Grab tech articles daily from UGC communities
JavaScript
77
star
12

react-native-image-viewer

A pure JavaScript image viewer component for react-native apps with pan, pinch.etc, supporting both iOS and Android.
JavaScript
67
star
13

codewars-practices

Some best practices for practice questions on codewars, update it weekly
67
star
14

react-area-linkage

็œๅธ‚ๅŒบ่”ๅŠจ้€‰ๆ‹ฉ: https://dwqs.github.io/react-area-linkage/
JavaScript
61
star
15

react-virtual-list

A tiny virtualization list component(gzipped 6KB), supports dynamic height: https://dwqs.github.io/react-virtual-list/
JavaScript
46
star
16

vue-startup

A template with webpack 4 + vuejs 2 + + babel 7 setup for projects startup
JavaScript
43
star
17

chare

A simple CLI scaffolding for front-end projects
JavaScript
35
star
18

vue-resume

A Personal Resume Template is powered by Vue,Node.js & Webpack:http://resume.ido321.com
Vue
34
star
19

react-demos

Some react demos for myself: https://dwqs.github.io/react-demos
JavaScript
33
star
20

node-style-guide

A guide for styling your node.js / JavaScript code.
32
star
21

v2-lazy-list

A simple lazy-load list component based Vue 2.x: https://dwqs.github.io/v2-lazy-list/
JavaScript
31
star
22

mp-jithub

Mini program for Github
Vue
30
star
23

vue-typescript

A template with webpack 4 + vuejs 2 + typescript 2 setup for projects startup
TypeScript
27
star
24

revuejs

๐Ÿ‡ A tiny, light and handy state management for vuejs 2, writing less verbose code.
JavaScript
24
star
25

vue-toast

A toast component written with Vue, designed based on Ant Design [deprecated]
Vue
18
star
26

webpack-mpvue-startup

A template with webpack 3 + mpvue 1 setup for projects startup
JavaScript
14
star
27

beautify-scrollbar

Beautify browser's scrollbars: https://dwqs.github.io/beautify-scrollbar/index
JavaScript
13
star
28

lue

๐ŸŒฑ Vue and vuex based library, writing less verbose code.
JavaScript
12
star
29

mpvue-markdown-parser

A markdown parser for mpvue
JavaScript
9
star
30

nx

A hexo theme based on landscape-plus
CSS
9
star
31

babel-plugin-on-demand-import

Babel plugin for importing components on demand
JavaScript
9
star
32

react-startup

A template with webpack 4 + react 16 + react-router 4 + babel 7 setup for projects startup
JavaScript
8
star
33

chrome-extension-for-wiki

๐Ÿ” ๐Ÿฎ ๐Ÿผ Add awesome article link to your wiki repo on github quickly./ๅฟซ้€ŸๆทปๅŠ ๆ–‡็ซ ้“พๆŽฅๅˆฐ wiki repo ็š„ chrome ๆ‰ฉๅฑ•
JavaScript
7
star
34

async-await-error-handling

Error handling friendly for async/await in ts and js
JavaScript
7
star
35

reproto

A tool for generate simple random password which contains letters, number and special characters
JavaScript
6
star
36

icons

Some interesting icon & design implemented by pure css.
5
star
37

orbithub

A chrome extensition for convenient github search
JavaScript
5
star
38

redux-actions-promise

๐Ÿฐ ๐Ÿฑ ๐Ÿป FSA-compliant promise middleware for Redux, supports referencing dispatcher/state in action.
TypeScript
5
star
39

maoxuan

ๆ•™ๅ‘˜้€‰้›†้˜…่ฏป็ฌ”่ฎฐ
5
star
40

tiny-dom-helpers

๐ŸŒœ ๐ŸŒš ๐ŸŒ› Tiny dom helpers, supports IE9 +.
JavaScript
5
star
41

scroll-on-webview

ๅค„็† webview ไธŠ็š„ๆปšๅŠจ
JavaScript
4
star
42

infine

A chrome extension for theme color replacement of Github
CSS
4
star
43

note

Personal note sites, write what you want, support markdown: http://note.ido321.com/
JavaScript
3
star
44

view-star-packages-on-npm

View your star packages on npmjs.com: https://dwqs.github.io/view-star-packages-on-npm
JavaScript
3
star
45

async-react-compoment

๐Ÿ˜Ž ๐Ÿ‘€ ๐Ÿ™ˆ Async component loaded based webpack 3 for react-router 4.[unmaintained]
TypeScript
2
star
46

gitlang

Repository to list all programming languages github supports
JavaScript
2
star