1

I am try add 1, but item.num is 01. How to add 1 input value is 1,2,3,4,5...? Note that num must be the string. Go the demo of jsfiddle.

Look at the gif:

enter image description here

Look at the image:

enter image description here

Note:item.num += 1 do not need to modify!

enter image description here

I want the following effect:

enter image description here

Look at the javascript:

var app = new Vue({
  el: "#app",
  data: {
    list: [{
      id: "1",
      name: "demo01",
      num: "0"
    }],
    addnum: []
  },
  methods: {
    addClick(item) {
      console.log(this.addnum.push(item))
      item.num+=1
    },

  }
})

HTML file:

<div id="app">
  <ul>
    <li v-for="item in list">
      <p>{{item.name}}</p>
      <br>
      <input type="text" :value="item.num">
      <button @click="addClick(item)">+</button>
    </li>
  </ul>
</div>
wen tian
  • 433
  • 2
  • 5
  • 18

1 Answers1

3

Hoping that you can at least add some code to addClick method, here's what to do:

addClick(item) {
      console.log(this.addnum.push(item))
      item.num = parseInt(item.num, 10)
      item.num+=1
      item.num = ""+item.num // converting back to string
    },
mehulmpt
  • 15,861
  • 12
  • 48
  • 88