Vue js to react js

Viewed 3859

Is there a (good) tool out there that can convert vue js into react js? I'm pretty new to react in the first place, so I do not have time to learn vue js right now. If anyone has any good tools or tips for me, that would be great.

The code is part of a project for creating a video display.

If anyone's interested in the code I'm trying to convert to react js:

    const videos = [
  {
    id: "1",
    name: "What Happens if You Fall Into a Black Hole?",
    smallImg:
      "https://d2r55xnwy6nx47.cloudfront.net/uploads/2015/05/InTheory_Ft_BH_1920x10801-520x293.jpg",
    largeImg:
      "https://d2r55xnwy6nx47.cloudfront.net/uploads/2015/05/InTheory_Ft_BH_1920x10801-1720x968.jpg",
    duration: "2:18",
    active: true,
    description:
      "Filming by Petr Stepanek. Editing and motion graphics by MK12. Music by Steven Gutheinz.",
    videoURL:
      "https://www.youtube-nocookie.com/embed/ScMzIvxBSi4?rel=0&enablejsapi=1",
  },
  {
    id: "2",
    name: "A ‘Rebel’ Without a Ph.D.",
    smallImg:
      "https://d2r55xnwy6nx47.cloudfront.net/uploads/2017/04/DysonPaintingStill-520x293.jpg",
    largeImg:
      "https://d2r55xnwy6nx47.cloudfront.net/uploads/2017/04/DysonPaintingStill.jpg",
    duration: "2:18",
    active: false,
    videoURL:
      "https://www.youtube.com/watch?v=uleWdBDmjNg?rel=0&enablejsapi=1",
  },
  {
    id: "3",
    name: "Pencils Down: The Art of Teaching Math and Science",
    smallImg:
      "https://d2r55xnwy6nx47.cloudfront.net/uploads/2016/10/2015-05-26-14.48.01-520x390.jpg",
    largeImg:
      "https://d2r55xnwy6nx47.cloudfront.net/uploads/2016/10/2015-05-26-14.48.01-1720x1290.jpg",
    duration: "2:35",
    active: false,
    videoURL:
      "https://www.youtube-nocookie.com/embed/ScMzIvxBSi4?rel=0&enablejsapi=1",
  },
  {
    id: "4",
    name: "A Tenacious Explorer of Abstract Surfaces",
    smallImg:
      "https://d2r55xnwy6nx47.cloudfront.net/uploads/2016/10/2015-05-26-14.48.01-520x390.jpg",
    largeImg:
      "https://d2r55xnwy6nx47.cloudfront.net/uploads/2016/10/2015-05-26-14.48.01-1720x1290.jpg",
    duration: "2:35",
    active: false,
    videoURL:
      "https://www.youtube.com/watch?v=uleWdBDmjNg?rel=0&enablejsapi=1",
  },
];

Vue.component("video-show-component", {
  template: `
<div>{{getActiveVideo.description}}
<div>
 <iframe
              allowFullScreen
              frameborder="0"
              height="376"
              :src="video.videoURL"
              style="width: 100%; min-width: 536px"
            />
    </div>
    </div>`,
  props: {
    video: Object,
  },
  methods: {
    setActive() {
      videos.map((video) => {
        video.active = this.video.id === video.id;
      });
    },
  },
});

Vue.component("video-list-component", {
  template: `
    <div class="video-card"
         :class="[{ 'active': video.active }]" @click="setActive(video.id)">

      <div class="video-card-thumb">
      <div class="image-container aspect-ratio-16by9">
      
        <div 
        class="image-background"
        :style="{ backgroundImage: 'url(' + video.smallImg + ')' }"
      ></div>
      <div class="image-content-container">
              <div class="video-play-icon"><img src="data:image/svg+xml;base64,PHN2ZyBoZWlnaHQ9JzIwMCcgd2lkdGg9JzIwMCcgIGZpbGw9IiM1MUE3RjkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHZlcnNpb249IjEuMSIgeD0iMHB4IiB5PSIwcHgiIHZpZXdCb3g9IjAgMCAxMDAgMTAwIiBzdHlsZT0iZW5hYmxlLWJhY2tncm91bmQ6bmV3IDAgMCAxMDAgMTAwOyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+PHBhdGggZD0iTTg2LDU1LjVjLTAuNiwxLTEuNSwxLjgtMi41LDIuNEwyNi42LDg3LjljLTAuOSwwLjUtMiwwLjctMywwLjdjLTMuNiwwLTYuNC0yLjktNi40LTYuNFYxNy44ICBjMC0zLjYsMi45LTYuNCw2LjQtNi40YzEuMiwwLDIuMywwLjMsMy4zLDAuOWw1Ni45LDM0LjNDODYuOCw0OC41LDg3LjgsNTIuNCw4Niw1NS41eiI+PC9wYXRoPjwvc3ZnPg=="></div>
              </div>
      </div>
      </div>
      <div class="video-card-content">
      <div class="video-title">{{video.name}}</div>  
      <div class="video-duration">{{video.duration}}</div>
</div>
  </div>
    </div>
  `,
  props: {
    video: Object,
  },
  methods: {
    setActive() {
      videos.map((video) => {
        video.active = this.video.id === video.id;
      });
    },
  },
});

new Vue({
  el: "#app",
  data: {
    activeVideo: {},
    videos,
  },
  computed: {
    getActiveVideo() {
      return this.filterVideos();
    },
  },
  methods: {
    filterVideos() {
      return this.videos.find((video) => {
        return video.active;
      });
    },
  },
});
3 Answers

React and Vue have incompatibilities, thus a converter wouldn't make sense, or at best generate unreadable code, that may not cover all edge cases. Your best option is to rewrite the logic in react

There is no such thing because it is not just about the templating, but also how you do compose your lifecycles/manage your state/split your components. If you want to use React, the fastest way (and also cleanest) is still to learn it from the ground up.

You could use something like this but yeah, be sure that it will fall poorly on you quick enough, especially if you do not use SFC files as of here.

No, But react is easy to learn. React just javascript and some ideas. And some similarities between Vue Js and react. If you know Vue Js then it's easy to learn to react Js for you.

Related