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-React를 사용하여 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 v-bind v-on , v-text 및 v-html : 부분 내장 VUE 지침 (SFC) 만 지원합니다. // 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 ;
}
// ... 이 저장소는 MIT 아래에 출시됩니다.