vue 实现点击事件显示隐藏

<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			#box {
				width: 50px;
				height: 50px;
				background: red;
			}
		</style>
	</head>

	<body>
		<div id="app">
			<button @click="click">{
    {message}}</button>

			<div id="box" v-show="isShow"></div>
		</div>
		
	</body>
	<script src="js/vue.js"></script>
	<script>
		var app = new Vue({
			el: '#app',
			data: {
				isShow: false,
				message: '显示'
			},
			methods: {
				click() {
					this.isShow = !this.isShow;
					if(this.isShow){
						this.message='隐藏';
					}else{
						this.message='显示';
					}
				}
			}
		})
	</script>

</html>

  

转载于:https://www.cnblogs.com/150536FBB/p/10166946.html

    原文作者:weixin_30700977
    原文地址: https://blog.csdn.net/weixin_30700977/article/details/99582120
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞