两者都可以有条件地显示元素,但它们的实现方式不同 — v-if 从 DOM 中添加/移除元素;v-show 将其保留在 DOM 中并切换其 CSS display。
vue
<template>
<p v-if="isVisible">Rendered only when true (removed from DOM when false)</p>
<p v-show="isVisible">Always in the DOM; just display:none when false</p>
</template>
实际上发生了什么
html
...
