条件渲染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>

点击按钮前

vue2.0 之条件渲染

vue2.0 之条件渲染

点击按钮后

vue2.0 之条件渲染

vue2.0 之条件渲染

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 之条件渲染

vue2.0 之条件渲染

点击按钮后

vue2.0 之条件渲染

vue2.0 之条件渲染

 

相关文章:

  • 2021-07-12
  • 2022-01-26
  • 2021-11-12
  • 2021-10-20
  • 2022-02-20
  • 2021-11-03
猜你喜欢
  • 2021-09-03
  • 2021-08-23
  • 2021-09-01
  • 2022-12-23
相关资源
相似解决方案