vue 预览v-html 富文本里的图片 使用vant

1 篇文章 0 订阅

我的用的vue2.0 

# Vue 2 项目,安装 Vant 2:

npm i vant@latest-v2 -S

main.js

import Vant from "vant"
import 'vant/lib/index.css';
Vue.use(Vant)
<template>
  <div class="wrap">
    <!--type == 5是推广页是纯H5 contentType != 1 也是纯H5-->
    <video v-if="info.type != 5 && info.contentType == 1" :src="info.content" :poster="coverImage" controls class="video-style"></video>   
    <div v-if="info.type != 5" class="title">
      <div class="d1">{{ info.name }}</div>
      <div class="d2">{{ info.createDate }}</div>
    </div>
    <div v-if="info.type != 5" class="share">
      <div class="create-by">{{info.createBy ? (info.createBy != 'admin' ? info.createBy : '管理员') : ''}}</div>
    </div>
    <!--真正使用的地方vant预览富文本里的图片-->
    <div v-html="info.brief" class="content" @click="judgeImg($event)"></div> 
  </div>
</template>

<script>
import { getTrainingDetail } from "@/api/course/training";
import {ImagePreview} from "vant"  //引入vant预览图片组件

export default {
  metaInfo: {
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no' }
    ]
  },
  name: "webview",
  data () {
    return {
      info: {},
      coverImage: ''      
    };
  },
  watch: {
    $route: {
      handler: function (route) {
        this.redirect = route.query && route.query.redirect;
      },
      immediate: true
    }
  },
  created () {
    //console.log(this.$route.query.id)
    if(this.$route.query.id){
      this.handleView(this.$route.query.id)      
    }    
  },
  mounted() {
    document.title = '详情';
  },
  methods: {
    //判断是否为图片并提取当前图片地址
    judgeImg(e){
        if(e.target.tagName=="IMG" && e.target.currentSrc){
            this.previewSingleImg(e.target.currentSrc)
        }
    },
    //查看单个大图
    previewSingleImg(url) {
        ImagePreview({
            images: Array.of(url),
            startPosition: 0,
        });
    },

    handleView(id){
      getTrainingDetail(id).then(res => {
        if(res.code == 200){
          this.info = res.data
          if(this.info.name.length > 12){
            document.title = this.info.name.substring(0, 12);
          }else{
            document.title = this.info.name
          }
          this.coverImage = this.info.cover
        }
      });
    }
  }
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.video-style { display: block; width: 100%}
.title{ padding: 10px; display: flex;}
.title .d1{ flex: 1; color: #333; font-size: 18px; font-weight: bold;}
.title .d2{ padding-top: 6px; white-space: nowrap; font-size: 12px; color: #999;}
.content{ padding: 0 10px 40px 10px; font-size: 14px;}
.share{ margin-top: 10px; padding-left: 10px}
.create-by{ font-size: 14px; color: #333;}
.content img{ max-width: 100%;}
</style>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue Quill Editor是一个Vue富文本编辑器插件,它可以用于在Vue项目中进行富文本编辑。您可以通过安装Vue-Quill-Editor和Quill来使用它。 关于图片预览的问题,根据提供的引用内容,我没有找到直接关于富文本图片预览的说明。但是,根据Vue Quill Editor的使用方法,您可以使用自定义的toolbar来实现相关功能。您可以在toolbar中添加一个按钮,当用户点击该按钮时,触发一个方法来预览富文本中的图片。您可以使用Vue的v-if指令根据条件来显示或隐藏图片预览的组件。具体实现的代码如下所示: ``` <template> <div class="editor"> ... <!-- 自定义toolbar中增加图片预览按钮 --> <div id="my-toolbar"> ... <button @click="previewImages">预览图片</button> </div> ... </div> </template> <script setup> import { QuillEditor, Quill } from '@vueup/vue-quill' import { getCurrentInstance, ref } from "vue"; const { proxy } = getCurrentInstance(); const previewImages = () => { // 实现预览图片的逻辑 // 可以使用Quill的API获取富文本中的图片,然后展示在预览组件中 } </script> ``` 在上述代码中,您可以在`previewImages`方法中实现预览图片的逻辑。您可以使用Quill的API获取富文本中的图片,并将其显示在预览组件中。 需要注意的是,具体的图片预览逻辑和组件实现取决于您的具体需求和项目实现。您可以根据自己的情况进行适当的调整和扩展。 <span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Vue-Quill-Editor富文本编辑器的使用教程](https://download.csdn.net/download/weixin_38701952/13980065)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [使用vue-quill展示富文本内容](https://blog.csdn.net/qq_36576430/article/details/127793120)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值