0
点赞
收藏
分享

微信扫一扫

10. v-for

Ewall_熊猫 2022-03-24 阅读 144
vue.js
<script setup>
// This starter template is using Vue 3 <script setup> SFCs
// Check out https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup
import HelloWorld from './components/HelloWorld.vue'
</script>

<template>
  <div>
    <ol>
      <!--写法一,有错误提示,表示没有写key-->
      <li v-for="(item,i) in news ">{{item}}</li>
      <!--写法二,-->
      <li v-for="(item,i) in news " :key="i">{{item}}==>{{i}}</li>
    </ol>
    <ol>
      <!--写法三,数据包含对象-->
      <li v-for="(item,i) in news1 " :key="i">{{item.title}}--{{item.tag}}--{{item.num}}</li>
    </ol>
    <ol>
      <!--写法四,对象-->
      <li v-for="(item,i) in laochen " :key="i">{{item}}==>{{i}}</li>
    </ol>
    <ol>
      <!--写法五,效果一模一样-->
      <li v-for="(item,i) of laochen " :key="i">{{item}}==>{{i}}</li>
    </ol>
  </div>
</template>

<script>

export default{
  name:'App',
  data(){
    return{
      news:[
        '菅义伟明年奥运',
        '你好',
        '干你'
      ],
      //放入对象
      news1:[
        {
          title:"菅义伟明年奥运",
          tag:"菲",
          num:"50万"
        },
        {
          title:"北京冬奥会",
          tag:"菲",
          num:"40万"
        } 
      ],
      // 输出对象
      laochen:{
        name:"老城",
        age:30,
        type:"帅"
      }
    }
  },
  methods:{

  }
}
</script>

<style>
/* 表示类名 */
.active{
  background: yellowgreen;
}
</style>
举报

相关推荐

v-for

v-for 指令详解

10. 网络

10.指针

10. 信号

v-if vs v-show vs v-for

v-for中的key

0 条评论