Vue3 V-for例子

 使用reactive响应式定义数组变量(自动更新视图),通过v-for标签渲染 

<script setup>
import { reactive } from 'vue';

const Fruits = reactive([
    {
        "num": '1',
        "name": '苹果',
        "info": '苹果汁水丰富,可以生津止渴。'
    },
    {
        "num": '2',
        "name": '柠檬',
        "info": '柠檬具有生津止渴、化痰止咳的功效。'
    }
]);
</script>

<template>
    <div style="text-align: left; transform: translateY(-250px);"> <!-- 添加向上移动的样式 -->
        <div style="margin-bottom: 20px;">水果列表</div>

        <div style="width: 1000px;" v-for="fruit in Fruits" :key="fruit.num"> ▪ 水果编号: {{ fruit.num }} -- 水果名称: {{
            fruit.name }} --详细信息: {{ fruit.info }}</div>
    </div>
</template>

<style scoped>
</style>

 表格布局

 

<script setup>
import { reactive } from 'vue';

const Fruits = reactive([
  {
    "num": '1',
    "name": '苹果',
    "info": '苹果汁水丰富,可以生津止渴。'
  },
  {
    "num": '2',
    "name": '柠檬',
    "info": '柠檬具有生津止渴、化痰止咳的功效。'
  }
]);
</script>

<template>
    <div style="text-align: center;">
      <div style="margin-bottom: 20px;">水果列表</div>
      
      <table border="1 solid" cellspacing="0">
        <tr>
          <th>水果编号:</th>
          <th>水果名称:</th>
          <th>详细信息:</th>
        </tr>
        <tr v-for="fruit in Fruits" :key="fruit.num">
          <td>{{ fruit.num }}</td>
          <td>{{ fruit.name }}</td>
          <td>{{ fruit.info }}</td>
        </tr>
      </table>
    </div>
  </template>
  

  
  <style scoped>
  table {
    margin: auto;
  }
  </style>
  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值