Representación de listas en Vue (3-8)

Representación de listas en Vue

Matrices poligonales y objetos poligonales

Iterar sobre la matriz

最外层有没要div
<template></template><div></div>的区别
<template>不会有占位符<div>会有


<!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='./vue.js'></script>
</head>
<body>
  	
    <div id="app">
    
       <div v-for="(item, index) of list" 
            :key="item.id">
           <div>
               {
   
   {item.text}} ---- {
   
   {index}}
           </div>
           <span>
               {
   
   {item.text}}
           </span>
       </div>
      
    </div>    
    <script>
        var vm = new Vue({
     
     
            el: "#app",
            data: {
     
     
                list: [{
     
     
                    id: "010120201",
                    text: "hello"
                }, {
     
     
                    id: "010120202",
                    text: "Dell"
                }, {
     
     
                    id: "010120203",
                    text: "Lee"
                }]
            }
        })
    </script>
</body>
</html>

Itera sobre objetos
Inserte la descripción de la imagen aquí

(elemento, clave, índice) es una función.

  <div id="app">
        <div v-for="(item, key, index) of userInfo">
            {
   
   {item}} --- {
   
   {key}} -- {
   
   {index}}
        </div>
    </div>    
    <script>
        var vm = new Vue({
     
     
            el: "#app",
            data: {
     
     
               userInfo: {
     
     
                   name: "Dell",
                   age: 28,
                   gender: "male",
                   salary: "secret"
               }
            }
        })
    </script>

Supongo que te gusta

Origin blog.csdn.net/weixin_45647118/article/details/113909070
Recomendado
Clasificación