html Vue将类绑定到v-for循环中的元素

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html Vue将类绑定到v-for循环中的元素相关的知识,希望对你有一定的参考价值。

<template>
<div>
<div class="container-fluid">
<div class="row">
<div v-for="(value,index) in services" :key="value.id" class="col-4">
  <mdb-jumbotron class="mb-0 text-center hoverable p-4">
    <mdb-row>
      <mdb-col md="12">
      <div class="hidden-text" style="position:relative; z-index: 1;">
      
      <div class="hidden-content-container">
      <div class=""  :class="[{ 'hideContent' : value.showDetail }]" style="position:absolute; background:red;">
        {{value.showDetail}}Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
      </div>
      </div>
      </div>
        <mdb-view :src="value.img" alt="Sample image for first version of blog listing">
          <a><mdb-mask waves overlay="white-slight"/></a>
        </mdb-view>
      </mdb-col>
      <mdb-col md="12" class="text-md-left">
        <a href="#!" class="green-text">
          <h2 class="pb-1">
          <mdb-icon :icon="value.icon" class="pr-1" style="padding-right:10px !important;"/>{{value.service}}</h2> 
        </a>
        <ul class="dashed" v-for="values in value.info" :key="value.index">
          <li v-html="values.infoList"></li>
        </ul>
       <!-- <h4 style="font-size:20px;" class="h4 mb-4" v-html="value.info"></h4> !-->
        <div class="row">
        <div class="col-sm-6">
          <mdb-btn color="success" class="button-info">Enquire</mdb-btn>
        </div>
        <div class="col-sm-6">
        <mdb-btn color="success" class="button-info">Book Quote</mdb-btn>
        </div>
        <div class="col-sm-12">
          <mdb-btn @click="value.showDetail = !value.showDetail" color="success" class="button-info button numbering">Read more</mdb-btn>
        </div>
        </div>
      </mdb-col> 
    </mdb-row>
  </mdb-jumbotron>
  </div>
  </div>
  </div>
  </div>
</template>

<script>
  import { mdbJumbotron, mdbRow, mdbCol, mdbView, mdbBtn, mdbIcon, mdbMask } from 'mdbvue';
  export default {
    name: 'Offer',
    components: {
      mdbJumbotron,
      mdbView,
      mdbMask,
      mdbIcon,
      mdbRow,
      mdbCol,
      mdbBtn
    },
    data() {
      return {
        services: [
          {
            id:1,
            showDetail: true,
            service: 'RESIDENTIAL',
            info:[
              {infoList:'Split Systems'},
              {infoList:'Ducted Systems'},
              {infoList:'Installation'},
              {infoList:'maintenance'}
              ],
            icon: 'home',
            img : 'https://www.airpro.com.au/wp-content/uploads/2016/03/airconditioning-03.jpg'
            },
          {
            id:2,
            showDetail: true,
            service: 'Commercial',
            info:[
              {infoList:'Refrigeration'},
              {infoList:'Installation'},
              {infoList:'Breakdown Service'}
              ],
            icon: 'industry',
            img: 'http://cdn2.hubspot.net/hub/495536/file-3142229012-jpg/blog-files/residential-rooftop-ac.jpg'
            },
          {
            id:3,
            showDetail: true,
            service: 'BOOK A DEMO',
            icon: 'wrench',
            img: 'https://cdn.jarviscars.com.au/content-img/btn-bookService.png'
            }
          ]
      }
    },

    computed: {
      
    },
    methods: {
      
    }
  }
</script>

<style lang="scss" scoped>
.hideContent {
  display:none;
}
.button-info {
  width:100%;
  padding: 10px;
}

.green-text h6{
  padding-top: 10px;
}

ul.dashed {
  list-style-type: none;
  padding-left:20px;
}
ul.dashed > li {
  text-indent: -5px;
  font-size:18px;
}
ul.dashed > li:before {
  content: "-";
  text-indent: -5px;
  position: relative;
  left: -8px;
}

</style>

以上是关于html Vue将类绑定到v-for循环中的元素的主要内容,如果未能解决你的问题,请参考以下文章

vue循环语句v-for中元素绑定值问题

前端Vue- v-for 循环中删除 元素;

Vue.js 循环语句

Vue.js v-for 循环绑定数组中的项目对象并在更改时更新

vue在for循环中绑定html数据属性

for循环中的Vue插槽范围