Giter Site home page Giter Site logo

havefive / react-vue Goto Github PK

View Code? Open in Web Editor NEW

This project forked from smallcomfort/react-vue

0.0 2.0 0.0 18.71 MB

Run Vue in React and React Native

License: MIT License

CSS 0.69% HTML 0.98% JavaScript 97.73% Shell 0.14% Vue 0.02% TypeScript 0.45%

react-vue's Introduction

React-Vue

React-Vue is designed to connect React and Vue. Which help you run Vue in React.

There are three uses.

Reactivity System

Thanks to Vue's clear hierarchical design, we can easily pull out the reactivity system (9 KB gzipped), and drive React component rendering.

npm install --save react-vue
import React, { Component } from 'react';
import Vue, { observer } from 'react-vue';

const store = new Vue({
  data () {
    return {
      count: 0
    }
  },
  methods: {
    increase () {
      this.count ++;
    }
  }
});

@observer
export default class Demo extends Component {
  render () {
    return <h1 onClick={store.increase}>{store.count}</h1>;
  }
}

document

Vue Component

Introduce react-vue-loader, which compile the Vue component into a React component. As you might think, your previously written Vue components can run inside the React component, and your React components can also run inside the Vue component.

npm install --save react-vue react-vue-helper
npm install --save-dev react-vue-loader
// One.js
import 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.js
import React, { Component } from 'react';

export default class Three extends Component {
  render () {
    return <span>{this.props.children}</span>
  }
}

document

Native

Introduce react-vue-native-scripts, which start a server to compile the vue component into a react component.

npm install --save react-vue react-vue-helper
npm install --save-dev react-vue-native-scripts

All React Native Components exists as built-in components in Vue, you can use react native components as following

<template>
  <view>
    <view>
      <text>Hello react vue</text>
    </view>
    <animated:view>
      <text>Hello animation</text>
    </animated:view>
  </view>
</template>

The similar JSX code is as follows

import React, { Component } from 'react';
import { View, Text, Animated } from 'react-native';

export default class Demo extends Component {
  render() {
    return (
      <View>
        <View>
          <Text>Hello react native</Text>
        </View>
        <Animated.View>
          <Text>Hello animation</Text>
        </Animated.View>
      </View>
    );
  }
}

You can use all the React Native API in Vue component. The camelCased prop names need to use their kebab-case (hyphen-delimited) equivalents

document

License

MIT

react-vue's People

Contributors

yyx990803 avatar defcc avatar kazupon avatar smallcomfort avatar jinjiang avatar posva avatar phanan avatar s-you avatar herringtondarkholme avatar chrisvfritz avatar ktsn avatar blake-newman avatar kingwl avatar hanks10100 avatar javoski avatar kingmario avatar dsonet avatar bluemsn avatar bartlomieju avatar mingmingwon avatar fnlctrl avatar yantene avatar gebilaoxiong avatar jingsam avatar zephraph avatar tejitak avatar znck avatar asheb avatar xqin avatar ralphite avatar

Watchers

zhaocai avatar  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.