程序员的资源宝库

网站首页 > gitee 正文

Vue快速集成合集!

sanyeah 2024-04-09 20:02:20 gitee 5 ℃ 0 评论

1、vue使用 Markdown编辑器(mavon-editor)

1、下载

npm install mavon-editor -S

2、全局注册

 // main.js全局注册
 import mavonEditor from 'mavon-editor'
 import 'mavon-editor/dist/css/index.css'
 // use
 Vue.use(mavonEditor)

3、Vue页面使用

 <div>
     <mavon-editor ref="md" v-model="value" :ishljs="true" @imgAdd="imgAdd"/>
 </div>
 ?
 <!-- 预览 -->
 <mavon-editor
     class="md"
     :value="article.content"
     :subfield="false"
     :defaultOpen="'preview'"
     :toolbarsFlag="false"
     :editable="false"
     :scrollStyle="true"
     :ishljs="true"
 />
 ?
  // 绑定@imgAdd event
 imgAdd(pos, $file) {
   let $vm = this.$refs.md
   // 第一步.将图片上传到服务器.
   const formData = new FormData();
   formData.append('file', $file);
   axios({
     url: 'http://localhost:9090/file/upload',
     method: 'post',
     data: formData,
     headers: {'Content-Type': 'multipart/form-data'},
   }).then((res) => {
     // 第二步.将返回的url替换到文本原位置![...](./0) -> ![...](url)
     $vm.$img2Url(pos, res.data);
   })
 }

Gitee地址:https://gitee.com/xiangyut/mavonEditor/

npmjs官网:https://www.npmjs.com/package/wlt-mavon-editor

2、Vue集成视频播放插件vue-video-player

1、安装:

npm install vue-video-player --save

2、引入!

全局引入

import Vue from 'vue'
import VueVideoPlayer from 'vue-video-player'

// require videojs style
import 'video.js/dist/video-js.css'
// import 'vue-video-player/src/custom-theme.css'

Vue.use(VueVideoPlayer, /* {
  options: global default options,
  events: global videojs events
} */)

组件引入

// require styles
import 'video.js/dist/video-js.css'

import { videoPlayer } from 'vue-video-player'

export default {
  components: {
    videoPlayer
  }
}

3、创建vueVideoPlayer.vue文件

4、建完成以后就要为这个vueVideoPlayer.vue这个文件夹填充内容了template里面的内容:

<template>
    <video-player class="video-player vjs-custom-skin"
                    ref="videoPlayer"
                    :playsinline="true"
                    :options="playerOptions0">
      </video-player>
</template>

 5、引入下载的包!

// require styles
import 'video.js/dist/video-js.css'

import { videoPlayer } from 'vue-video-player'

export default {
  components: {
    videoPlayer
  }
}

6、JS代码!

<script>
export default {
  name: 'vueVideoPlayer',
  data () {
    return {
      playerOptions0: {
        // 播放速度
        playbackRates: [0.5, 1.0, 1.5, 2.0],
        // 如果true,浏览器准备好时开始回放。
        autoplay: false,
        // 默认情况下将会消除任何音频。
        muted: false,
        // 导致视频一结束就重新开始。
        loop: false,
        // 建议浏览器在<video>加载元素后是否应该开始下载视频数据。auto浏览器选择最佳行为,立即开始加载视频(如果浏览器支持)
        preload: 'auto',
        language: 'zh-CN',
        // 将播放器置于流畅模式,并在计算播放器的动态大小时使用该值。值应该代表一个比例 - 用冒号分隔的两个数字(例如"16:9"或"4:3")
        aspectRatio: '16:9',
        // 当true时,Video.js player将拥有流体大小。换句话说,它将按比例缩放以适应其容器。
        fluid: true,
        sources: [
          {
            // 类型
            type: 'video/mp4',
            // url地址
            src: ''
          }, {
            // 类型
            type: 'video/mp4',
            // url地址 http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4
            src: ''
          }, {
            type: 'application/x-mpegURL', // 这里的种类支持很多种:基本视频格式、直播、流媒体等,具体可以参看git网址项目
            src: 'http://hls01open.ys7.com/openlive/6d499d610a0c4a6182e36ac7dca124ad.m3u8' // url地址
          }
        ],
        // 你的封面地址
        poster: '',
        // 允许覆盖Video.js无法播放媒体源时显示的默认信息。
        notSupportedMessage: '此视频暂无法播放,请稍后再试',
        controlBar: {
          timeDivider: true,
          durationDisplay: true,
          remainingTimeDisplay: false,
          // 全屏按钮
          fullscreenToggle: true
        }
      }
    }
  }
}
</script>
 
<style scoped>
.demo{
  display: inline-block;
  width: 600px;
  height: auto;
  text-align: center;
  line-height: 100px;
  border: 1px solid transparent;
  border-radius: 4px;
  overflow: hidden;
  background: #fff;
  position: relative;
  /* box-shadow: 0 1px 1px rgba(0, 0, 0, .2); */
 
}
 
.demo:hover{
  display: block;
}
.vjs-custom-skin > .video-js .vjs-big-play-button {
  transform: scale(0.6) !important;
}
</style>

 7、动态设置视频地址!

this.playerOptions['sources'][0]['src'] = src

npmjs.com官网:https://www.npmjs.com/package/vue-video-player

Github官网:https://github.com/surmon-china/vue-video-player

 

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表