首页 > 其他 > 详细

vue2.0 之条件渲染

时间:2017-06-25 23:02:36      阅读:264      评论:0      收藏:0      [点我收藏+]

条件渲染v-if、v-show

<template>
  <div>
    <a v-if="isPartA">partA</a>
    <a v-show="!isPartA">partB</a>
    <button v-on:click="toggle">toggle</button>
  </div>
</template>

<script>
  export default {
    data () {
      return {
        isPartA: true
      }
    },
    methods: {
      toggle () {
        this.isPartA = !this.isPartA
      }
    }
  }
</script>

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

点击按钮前

技术分享

技术分享

点击按钮后

技术分享

技术分享

v-if和v-show区别:

  • v-if删除
  • v-show用css控制

 

v-if、v-else

<template>
  <div>
    <a v-if="isPartA">partA</a>
    <a v-else>no data</a>
    <button v-on:click="toggle">toggle</button>
  </div>
</template>

<script>
  export default {
    data () {
      return {
        isPartA: true
      }
    },
    methods: {
      toggle () {
        this.isPartA = !this.isPartA
      }
    }
  }
</script>

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

点击按钮前

技术分享

技术分享

点击按钮后

技术分享

技术分享

 

vue2.0 之条件渲染

原文:http://www.cnblogs.com/shhnwangjian/p/7078372.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!