码迷,mamicode.com
首页 > 其他好文 > 详细

vue2.0 之列表渲染-v-for

时间:2017-06-24 23:41:09      阅读:263      评论:0      收藏:0      [点我收藏+]

标签:list   技术分享   app   text   item   rom   microsoft   height   log   

v-for 数组渲染

App.vue代码

<template>
  <div>
    <ul>
      <li v-for="item in list"> {{ item.name }} - {{ item.price }}</li>
    </ul>
    <ul>
      <li v-for="item in list" v-text="item.name + ‘-‘ + item.price"></li>
    </ul>
    <ul>
      <li v-for="(item, index) in list"> {{ index }} - {{ item.name }} - {{ item.price }}</li>
    </ul>
  </div>
</template>

<script>
  export default {
    data () {
      return {
        list: [
          {
            name: ‘apple 7S‘,
            price: 6188
          },
          {
            name: ‘huawei P10‘,
            price: 4288
          },
          {
            name: ‘mi6‘,
            price: 2999
          }
        ]
      }
    }
  }
</script>

<style>
  html {
    height: 100%;
  }
</style>

页面效果

技术分享

 

v-for 对象渲染

App.vue代码

<template>
  <div>
    <ul>
      <li v-for="value in objlist"> {{ value }}</li>
    </ul>
    <ul>
      <li v-for="(key, value) in objlist"> {{ key + ‘:‘ + value }}</li>
    </ul>
  </div>
</template>

<script>
  export default {
    data () {
      return {
        objlist: {
          name: ‘apple 7S‘,
          price: 6188,
          color: ‘red‘,
          size: 6.0
        }
      }
    }
  }
</script>

<style>
  html {
    height: 100%;
  }
</style>

页面显示

技术分享

 

v-for  子组件渲染

创建./components/hello.vue文件

<template>
  <div>
    {{ hello }}
  </div>
</template>

<script>
  export default {
    data () {
      return {
        hello: ‘i am component hello‘
      }
    }
  }
</script>

<style scoped>/**/
h1 {
  height: 100px;
}
</style>

App.vue代码

<template>
  <div>
    <componenthello v-for="(key, value) in objlist"></componenthello>
  </div>
</template>

<script>
  import componenthello from ‘./components/hello‘
  export default {
    components: {
      componenthello
    },
    data () {
      return {
        objlist: {
          name: ‘apple 7S‘,
          price: 6188,
          color: ‘red‘,
          size: 6.0
        }
      }
    }
  }
</script>

<style>
  html {
    height: 100%;
  }
</style>

页面显示

技术分享

 

vue2.0 之列表渲染-v-for

标签:list   技术分享   app   text   item   rom   microsoft   height   log   

原文地址:http://www.cnblogs.com/shhnwangjian/p/7074737.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!