Skip to content

Instantly share code, notes, and snippets.

@egoist
Last active January 7, 2016 08:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save egoist/f6deb4afad388387215d to your computer and use it in GitHub Desktop.
Save egoist/f6deb4afad388387215d to your computer and use it in GitHub Desktop.
Compile jQuery to XXX component

form jQuery:

<div class="bingo">
  <button>Say hi!</button>
</div>

<script>
  $('button').on('click', function () {
    console.log('hi')
  })
</script>

to Vue:

<template>
  <div class="bingo">
    <button @click="handleClick">Say hi!</button>
  </div>
</template>

<script>
  export default {
    methods: {
      handleClick() {
        console.log('hi')
      }
    }  
  }
</script>

to React:

class Bingo extends Component {
  handleClick() {
    console.log('hi')
  }
  render() {
    return (
      <div class="bingo">
        <button onClick={this.handleClick}>Say hi!</button>
      </div>
    )
  }
}
@egoist
Copy link
Author

egoist commented Jan 7, 2016

I will make the Vue version first, let's see how long it takes in order to make the plan for React version.

@egoist
Copy link
Author

egoist commented Jan 7, 2016

Compile between Vue and React sounds great too! (eh, did I speak proper English?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment