I'm trying Vue.js out but I am running into a problem. I am following a tutorial over at Laracasts but my v-for isn't working.
HTML:
<div id="root">
<ul>
<li v-for="name in names" v-text="name"></li>
</ul>
<input type="text" v-model="newName">
<button @click="addName">Add Name</button>
</div>
JS:
new Vue({
el: '#root',
data: {
newName: '',
names: ['John', 'Mike']
}
methods: {
addName() {
this.names.push(this.newName);
this.newName = '';
}
}
})
Fiddle: https://jsfiddle.net/4pb1f4uq/
If it helps, the link to the Laracast with episode: https://laracasts.com/series/learn-vue-2-step-by-step/episodes/4?autoplay=true
js applications are typically very fast and responsive due to their lightweight nature. Vue is considered a child of the JavaScript frameworks Angular and React. Created by Evan You in 2013 (released in 2014), Vue has gained popularity rapidly.
Vue is lightweight, easy to learn, pleasant to write in, and not difficult to integrate with legacy technologies or an application without a specified framework. Because of its familiar templating syntax and use of components, integrating or migrating existing projects to Vue is faster and smoother.
Vue 2 has now entered maintenance mode: it will no longer ship new features, but will continue to receive critical bug fixes and security updates for 18 months starting from the 2.7 release date. This means Vue 2 will reach End of Life by the end of 2023.
Vue Template Refs give our Javascript code a reference to easily access the template. For example, if we needed quick access to a component or HTML element, template refs is the perfect solution. In Vue 3, the Composition API gives us another way to use template refs.
You are missing the comma after the data
object:
data: {
newName: '',
names: ['John', 'Mike']
}, // comma here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With