1.v-show指令的作用是:根据切换元素的显示状态
2.原理是修改元素 的display,实现显示隐藏
3.通过判断自定义值为true或false进行隐藏显示

下列是v-show最基本的引用方式

<template>
	<view class="" >
<image src="../../static/c1.png"  @click="cj()"></image>
<input type="text" value="" placeholder="我打打打" v-show="ww" />
		</view>

		
	</view>
	
</template>

<script>
	export default {
		data() {
			return {
				ww:true
				// www:true,
				// www:true
			}
		},
		methods: {
cj(){
	this.ww=!this.ww
	
}    
		}
	}
</script>

也可以直接在html中进行取反达到图片切换效果

<template>
	<view class="" >
<image src="../../static/c1.png"  @click="cj()" v-show="ww"></image>
<image src="../../static/c2.png"  @click="cj()" v-show="!ww"></image>

		</view>

		
	</view>
	
</template>

<script>
	export default {
		data() {
			return {
				ww:true
				// www:true,
				// www:true
			}
		},
		methods: {
cj(){
	this.ww=!this.ww
	
}    
		}
	}
</script>

Logo

基于 Vue 的企业级 UI 组件库和中后台系统解决方案,为数万开发者服务。

更多推荐