学习Vue的第二天

v-for 迭代对象

v-for 可以通过一个对象的属性来迭代数据:

<!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>
    <script src="https://unpkg.com/vue@next"></script>
  </head>
  <body>
    <div id="app">
      <ul>
        <template v-for="value in object">
          <li>{{ value }}</li>
        </template>
      </ul>
    </div>
    <script>
      const app = Vue.createApp({
        data() {
          return {
            object: {
              name: 'uriel',
              sex: 'male',
              slogan: 'Talk is cheap show my you code.',
            },
          }
        },
      })
      app.mount('#app')
    </script>
  </body>
</html>
posted @ 2022-04-27 14:55  wjxuriel  阅读(21)  评论(0)    收藏  举报