1、html代码

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <ul>
        <li v-for="item in hobby">{{item}}</li>
      </ul>
    </div>

    <script src="vue.js"></script>
    <script>
      const app = new Vue({
        el: '#app',
        data() {
          return {
            message: '你好',
            hobby: ['running', 'swimming', 'cooking'],
          }
        },
      })
    </script>
  </body>
</html>

2、备注
(1)使用v-for指令遍历data.hobby,如果在console添加

app.hobby.push("reading")

页面会显示
在这里插入图片描述

Logo

前往低代码交流专区

更多推荐