1:先展示一下成果
2-1:方法1 给父元素添加ref
let exl_examDescP = this.$refs.exl_examDescP;
for(let item of exl_examDescP){
if(item.firstElementChild.getElementsByTagName("img").length > 0){
console.log(111);
item.firstElementChild.append("[图片]...");
}
}
复制代码
v-html去编译成html; 但是在vue里mounted里拿不到refs,一直是undefined,后来在updated里面测试的效果是欧克的,但是写在updated里太耗费性能了,就开始思考另外一个方法; 方法二:正则匹配```
let imgReg = /<img[^>]*src[=\"\'\s]+[^\.]*\/([^\.]+)\.[^\"\']+[\"\']?[^>]*>/gi;
for(let item of list){
item.content = item.content.replace(imgReg, "[图片]...");
}
this.workList = list;
复制代码
在template里v-html=“item.content”,这样就欧克拉。