vue to react
1.0.0
尝试将VUE组件(支持JSX和SFC)转换为反应组件。
由于V0.0.8支持SFC
变换JSX组件:

变换SFC组件:

先决条件:node.js(> = 8.0)和npm(> = 5.0)
$ npm install vue - to - react - gUsage: 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
示例:
$ vtr -i my/vue/component上面的代码将把my/vue/component.js转换为${process.cwd()}/react.js 。
$ vtr -i my/vue/component -o my/vue -n test以上代码将把my/vue/component.js转换为my/vue/test.js 。
这是一个演示。
以下列表,当您使用vue-to-rexct将VUE组件转换以反应组件时,您应该注意:
// 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 >
)
}watch道具components 。请参阅组件提示。但是,当您转换SFC时,支持components支架。v-if , v-else , v-show , v-for ,V-bind, v-bind ,V-on, v-on , v-text ,V-Text和v-html 。 // Not support
< div : msg = "msg" @ click = "clickHandler" > < / div >
// Support
< div v-bind : msg = "msg" v-on : click = "clickHandler" > </ div > // Life-cycle methods relations mapping
const cycle = {
'created' : 'componentWillMount' ,
'mounted' : 'componentDidMount' ,
'updated' : 'componentDidUpdate' ,
'beforeDestroy' : 'componentWillUnmount' ,
'errorCaptured' : 'componentDidCatch' ,
'render' : 'render'
} ; // ...
computed: {
// support
test ( ) {
return your - computed - value ;
} ,
// not support
test2 : {
get ( ) { } ,
set ( ) { }
}
}
// ... // 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 ;
}
// ... 该仓库在麻省理工学院下发布。