vue使用$refs动态修改style,设置样式

在h5中,可以直接使用

this.$refs.indexChart.$el.style.display='none'

但是我打包运行成微信小程序,就会报错请添加图片描述
TypeError: Cannot read property ‘$el’ of undefined

目前解决办法,暂时没找到
这几个是我百度尝试使用$refs改变样式,都没有生效,所以h5推荐使用第一种!!!!简单粗暴!!!!!

// that.$refs.indexChart.setAttribute("class","vi")
//that.$refs.indexChart.style.display = "inline-block"
// that.$refs.indexChart.style = 'display: inline-block'

最后微信小程序,动态改变style,我选择了用三元表达式,当时还有别的方法。我暂时是用了这种

	<video 
		:class="[my? 'errorClass':'activeClass']" 
		src="https://digitalmanual.swellfun.com/miniprg_res/audio/diancang.mp4"
		ref="indexChart"
		>
	</video>
		

<script>
	export default{
		data(){
			return{
				my:true
			}
		},
		methods:{
			
		},
		onReady:function(){
			
			var that=this;
			setTimeout(function(){
				
					// that.$refs.indexChart.setAttribute("class","vi")
					//that.$refs.indexChart.style.display = "inline-block"
					// that.$refs.indexChart.style = 'display: inline-block'
						// that.$refs.indexChart.$el.style.display="inline-block"
				that.my=false
				console.log("11")
			},6000)
		},
	}
	
</script>

<style>
	.video{
		width: 100%;
		height: 216.35vw;
	}
	.errorClass{
		display: none;
		
	}
	.activeClass{
		display: inline-block;
		float: right;
		top: -800rpx;
	}
</style>

记录一下,免得忘记了。。。


版权声明:本文为qq_43628847原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。