我正在尝试使用v-show或v-if来切换模板的显示,如下面的代码所示。
我面临的问题是,尽管v-show不是一个懒惰的条件,但当我将showTemplate设置为false或true时,msg的内容始终显示。
请告诉我如何正确使用v-show和v-if。
helloWorld:
{{msg}}
应用程序:
template>![]()
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
你必须这样使用:
<template> // v-show或v-if都可以 <div v-show="showTemplate" class="hello"> {{msg}} </div> </template> <script> export default { name: 'HelloWorld', props: { msg: String } } </script> <script setup> import { ref } from 'vue' let showTemplate = ref(true) showTemplate.value=false </script>因为v-if或v-show不能与
template属性一起使用。