What is the instruction to hide elements in vue

青灯夜游
Release: 2022-12-15 10:37:06
Original
3437 people have browsed it

The command to hide elements in vue is "v-show". The v-show instruction determines whether an element is displayed or hidden based on the true or false value of the expression. The syntax is "v-show="expression"". The v-show instruction controls the display and hiding state of the element by changing the CSS display attribute of the element. The content of the expression following the instruction will eventually be parsed into a Boolean value. When the value is true (true), the element is displayed, and when the value is false (false) ) when the element is hidden.

What is the instruction to hide elements in vue

The operating environment of this tutorial: windows7 system, vue3 version, DELL G3 computer.

Vue.js provides a v-show directive, which determines whether to display or hide an element based on the true or false value of the following expression.

The v-show command controls the display and hidden state of the element by changing the display attribute of the element's css.

v-show instruction introduction

The v-show instruction needs to be followed by a Boolean variable or Boolean expression. When the value is true Shows the element when the value is false and hides the element when the value is false.

<标签 v-show="true/false"></标签>

<!--true:显示   false:隐藏-->
Copy after login

Example:

<div id="app">
    <p v-show="flag == &#39;显示&#39;">Vue 课程</p>
</div>
Copy after login
<script>
    var app = new Vue({
        el: &#39;#app&#39;,
        data: {
            flag: &#39;隐藏&#39;
        }
    });
</script>
Copy after login

When the flag is set to 'hide', "Vue Course" will not be displayed; when the flag is set to 'show', "Vue Course" will be displayed Vue Courses".

In fact, when the flag is set to 'hidden', the css attribute display of the p element is set to none, so the element is hidden.

The rendered code is as follows:

<p style="display: none;">Vue 课程</p>
Copy after login

v-show code example

The following are html and js code examples

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1.0">
		<title>v-show指令</title>
	</head>
	<body>
		<div id="app">
			<input type="button" value="切换显示" @click="changeIsShow" />
			<p v-show="isShow">不装了,我摊牌了,没错你要找的就是我</p>
		</div>
		<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
		<script>
			var  app = new Vue({
				el:"#app",
				data:{
					isShow:false
				},
				methods:{
					changeIsShow(){
						this.isShow = !this.isShow
					}
					
				}
			})
		</script>
	</body>
</html>
Copy after login

The code after rendering is as follows

<p style="display: none;">不装了,我摊牌了,没错你要找的就是我</p>
Copy after login

The running result of the code is as follows:

What is the instruction to hide elements in vue

Summary

  • The function of the v-show command is to switch the display state of the element based on the true or false value

  • The principle is to modify the element CSS property (display) determines whether to display or hide

  • The content following the directive will eventually be parsed into a Boolean value

  • The value is true (true ) when the element is displayed, and when the value is false (false), the element is hidden

  • After the data changes, the display status of the corresponding element will also be updated synchronously

[Related recommendations: vuejs video tutorial, web front-end development]

The above is the detailed content of What is the instruction to hide elements in vue. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
vue
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template