当前位置:   article > 正文

vue 从富文本文档中将照片的的路径取出_vue获取富文本中所有图片路径

vue获取富文本中所有图片路径

在以富文本文档存进数据库中后,有图片和文字叙述,网页需要将图片单独取出进行以下操作

  1. methods: {
  2. getInfo(){
  3. const id=this.$route.query.informationId;
  4. console.log(id+"详情id");
  5. getInformationInfo(id).then((ref)=>{
  6. console.log(ref.data);
  7. this.form=ref.data;
  8. const content=ref.data.informationContent;
  9. this.htmlContent=content.toString();
  10. console.log(this.htmlContent)
  11. })
  12. },
  13. getImageSrc() {
  14. // 创建一个临时元素,将HTML内容插入其中
  15. const tempElement = document.createElement('div');
  16. tempElement.innerHTML = this.htmlContent;
  17. // 查找 <img> 标签并获取 src 属性值
  18. const imgElement = tempElement.querySelector('img');
  19. if (imgElement) {
  20. const srcValue = imgElement.getAttribute('src');
  21. this.imagePath=srcValue
  22. console.log('Image src:', srcValue+"照片路径");
  23. } else {
  24. console.log('No <img> element found.');
  25. }
  26. },
  27. },

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/231552
推荐阅读
相关标签
  

闽ICP备14008679号