Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vue.js v-for not working

Tags:

html

vue.js

v-for

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

like image 591
S. Kanon Avatar asked Apr 19 '17 08:04

S. Kanon


People also ask

Is VueJS gaining popularity?

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.

Is VueJS difficult to learn?

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.

Is Vue 2 still supported?

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.

What is ref Vue 3?

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.


1 Answers

You are missing the comma after the data object:

data: {
  newName: '',
  names: ['John', 'Mike']
},  // comma here
like image 105
Decade Moon Avatar answered Sep 28 '22 16:09

Decade Moon