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>

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

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值