vue改变元素html,vue 通过v-html动态渲染的html元素 设置样式问题 $nextTick

例如,我们从后端接口中获取来这么一大串html代码需要填充至我们页面当中去

5bd0ecc1c382

image.png

通过v-html设置上去后,我们在style里面设置样式是设置不上去的

这个时候就要用到$nextTick,通过js来设置样式

if(res.data.code == 200) {

console.log(res)

let dataList = res.data.data.content

let text = document.getElementById('text')

for(let i = 0; i < dataList.length;i++) {

for(let j = 0; j < dataList[i].length;j++) {

this.text = dataList[i][0].post_content

this.$nextTick(function () {

for(let i = 0;i < text.children.length;i++) {

text.children[i].style.marginBottom = '20px'

text.children[i].children[0].style.fontSize = '12px'

text.children[i].children[0].style.lineHeight = '20px'

text.children[i].children[0].style.color = '#666666'

text.children[i].children[0].style.width = '100%'

if(text.children[2].children[0].nodeName == 'IMG') {

text.children[i].style.textIndent = 0

} else {

text.children[i].style.textIndent = '2em'

}

}

})

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值