学习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>
        <li v-for="(site, index) in sites">
          {{index}} -- {{site.text}}
        </li>
      </ul>
    </div>
    <script>
      const app = Vue.createApp({
        data() {
          return {
            sites: [{ text: 'Google' }, { text: 'Baidu' }, { text: 'Yandex' }],
          }
        },
      })
      app.mount('#app')
    </script>
  </body>
</html>

posted @ 2022-04-27 14:50  wjxuriel  阅读(21)  评论(0)    收藏  举报