React-Vue旨在连接React和Vue,帮助您在React中运行Vue。
用途:
使用Vue的Reactivity系统来观察React组件
使用react-vue-loader以在React应用中运行Vue组件
Reactivity系统感谢Vue层次分明的简洁设计,我们可以很容易的将reactivity系统导出(9KB压缩包),并在其上驱动React组件
npm install --save react-vueimport React, { Component } from 'react';import Vue, { observer } from 'react-vue';const store = new Vue({ data () { return { count: 0 } }, methods: { increase () { this.count ++; } }});@observerexport default class Demo extends Component { render () { return <h1 onClick={store.increase}>{store.count}</h1>; }}文档
Vue组件引入react-vue-loader可以将Vue组件编译成一个React组件。正如您所想的那样,您编写的Vue组件可以在React组件中运行,React组件也可以在Vue组件中运行。
npm install --save react-vue react-vue-helpernpm install --save-dev react-vue-loader// One.jsimport React, { Component } from 'react';import Two from './Two';export default class One extends Component { render() { return <Two>Hello Vue</Two>; }}<!-- Two.vue --><template> <div @click="count++"> <three>{{count}}</three> <slot></slot> </div></template><script> import Three from './Three' export default { components: { Three }, data () { return { count: 0 } } }</script>// Three.jsimport React, { Component } from 'react';export default class Three extends Component { render () { return <span>{this.props.children}</span> }}文档
评论