weixin_44645309
厕所打你
2021-01-27 22:23

vue数据未响应式更新

  • vue.js
  • javascript
<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>

<body>
  <div id="example">
    <ul>
      <li v-for="item in books">
        书名:{{item.name}}
        数量:{{item.amount}}
        <button @click="increment(item.amount)">+</button>
      </li>
    </ul>
  </div>
  <script type="text/javascript" src="D:/web/js/vue/vue.js"></script>
  <script>
    var app=new Vue({
      el: "#example",
      data: {
        books: [
          {
            name: 'js',
            amount: 1
          },
          {
            name: 'js',
            amount: 1
          }
        ]
      },
      methods: {
        increment(amount){
          amount++
        }
      }
    })

  </script>
</body>

</html>
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

4条回答