vue基础----用vue来展示表格数据

给刚学vue不就的兄弟,用bootstrop, 

  <div class="container">
      <table class="table table-condensed table-bordered">
        <tbody>
          <template v-for="(item,index) in attrs">
            <tr>
              <th :colspan="2" class="head">{{item.group}}</th>
            </tr>
            <tr v-for="(item1, index1) in item.attributes">
              <td class="desc">{{item1.name}}</td>
              <td v-html="getAttrHtml(item1)"></td>
            </tr>
          </template>
        </tbody>
      </table>
    </div>
  <script>
    const attrs = [
      {
        "group": "Physical",
        "attributes": [
          {
            "name": "Size",
            "value": "160.8 x 78.1 x 7.4 mm#6.33 x 3.07 x 0.29 inches"
          },
          {
            "name": "Weight",
            "value": "228 grams#8.03 ounces"
          }
        ]
      },
      {
        "group": "Display / Screen",
        "attributes": [
          {
            "name": "Description",
            "value": "Super Retina XDR display | 458 ppi"
          },
          {
            "name": "Resolution",
            "value": "2778 x 1284 pixels"
          },
          {
            "name": "Display Size",
            "value": "6.7 inches"
          }
        ]
      },
      {
        "group": "Processor",
        "attributes": [
          {
            "name": "Description",
            "value": "A14 Bionic chip"
          }
        ]
      },
      {
        "group": "Camera(s)",
        "attributes": [
          {
            "name": "Description",
            "value": "Pro 12MP camera system: Ultra Wide, Wide, and Telephoto cameras"
          }
        ]
      },
      {
        "group": "Battery",
        "attributes": [
          {
            "name": "Replaceable",
            "value": "No"
          }
        ]
      }
    ]
    const app = Vue.createApp({
      data() {
        return {
          attrs
        }
      },
      mounted() {
        console.log(attrs[0].group);
      },
      methods:{
        getAttrHtml(item1) {
          return  item1.value.replace("#","</br>")
        }
      }
  
    }).mount('#root')
  </script>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xiaodunmeng

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值