Skip to content
Advertisement

How to Convert Codepen to Vue.js?

I’m having trouble moving this pen to Vue.js

This is what my code looks like for The Vue app – I understand where the HTML, and CSS should go. Should I add the Javascript to the individual component, or add it to the App.vue file?

What I want to do is test this code in a view I can route to.

This is the Javascript from the pen:

JavaScript

This is what my code looks like in the component (with changes from research / guessing), the HTML is in tags above it:

JavaScript

Advertisement

Answer

You just need to remove the link on the first of the HTML templets, and make the <div id='#app'> is the root for the whole page as mentioned on [Vue Docs] 1

Vue will show an error, explaining that every component must have a single root element. You can fix this error by wrapping the template in a parent element

Also change data:{} to function data(){return{}} … because As mentioned on Vue Docs, that Data have to be a function

a component’s data option must be a function, so that each instance can maintain an independent copy of the returned data object:

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement