vue中引入js,然后new js里的方法
阿里云Web播放器Web端使用SDK说明:https://help.aliyun.com/document_detail/51991.html?spm=5176.11065259.1996646101.searchclickresult.15a92458LoTQhA
vue项目中要使用阿里云的播放器,步骤如下:
先在index.html中引入需要的js,css
<link rel="stylesheet" href="//g.alicdn.com/de/prismplayer/2.7.2/skins/default/aliplayer-min.css" /> <script src="//g.alicdn.com/de/prismplayer/2.7.2/aliplayer-h5-min.js"></script> <script src="//g.alicdn.com/de/prismplayer/2.7.2/json/json.min.js"></script>
Vue组件中
template代码:
<section class="playBox prism-player videoplayIfram" id="AlivideoPlay"></section>
id是必须的
script代码:
aliyunPlay () {/*eslint-disable*/this.player = newAliplayer({id:'AlivideoPlay', //template里定义的部分width: '100%',height:'100%',vid :this.AliUrl, //url (必须)playauth : this.playauth, //(必须)showBarTime: 3000000,qualitySort:"asc"}, function (player) {//console.log("播放器创建成功"); });}
Vue完整代码:
<template><transition name="slide"><div class="videoplayback"><div class="videoPlayTop"><div class="passwordTip" v-show="ifShowPassword">播放密码:{{passwordTip}}</div><div class="goBack" @click="videoplayHidden"><div class="imgDiv"><img src="http://static.crecgec.com/wxmobile/left_arrow.png"/></div></div><div class="videoOperation" @click="changeVocon"><div class="videoOperationImg"><img src="http://static.crecgec.com/wxmobile/videoOperation.png"/></div></div></div><div class="videoplay" ref='videoplay'><!--<iframe class="videoplayIfram" :src='AliUrl' frameborder=0 ></iframe>--><section class="playBox prism-player videoplayIfram" id="AlivideoPlay"></section><!-- <div class="prism-player videoplayIfram" id="prismPlayer"></div> --><div class="noVideoPlay" v-show="noVideoPlayShow">视频暂时无法播放</div></div><div class="videoOperationCon" v-show="voconShow"><div class="voconItem" v-if="favorite === null" @click="collectionYes"><div class="divImg"><img src="http://static.crecgec.com/wxmobile/collection.png"/></div><div class="divVal">收藏</div></div><div class="voconItem" v-else @click="collectionNo"><div class="divImg"><img src="http://static.crecgec.com/wxmobile/collectionHas.png"/></div><div class="divVal">已收藏</div></div><div class="voconItem" @click='shareopen'><div class="divImg"><img src="http://static.crecgec.com/wxmobile/share.png"/></div><div class="divVal">分享</div></div><div class="voconItem" @click="commentConShow"><div class="divImg"><img src="http://static.crecgec.com/wxmobile/scorEoperation.png"/></div><div class="divVal">评分</div></div></div><div class="commentShow" v-show="commentShow"><div class="commentCon"><div class="closeCommentCon"><a class="commentConClose" @click.stop="commentConClose"><div class="commentConCloseImg"><img src="http://static.crecgec.com/wxmobile/close.png"/></div></a></div><van-rateclass="scroeRate"v-model="scoreVal":size="25":count="5"color="#398ed1"void-color="#ceefe8"/><a class="commentSubmit" @click.stop="commentSubmit">提交</a></div></div><div class="playTitle">{{playTitle}}</div><div class="playDetails"><div class="detailsPlay"><div class="classHour">共{{classHour}}课时</div><a class="goCourseDetail" @click="videoplayHidden">课程详情></a></div></div><div class="catalog-list"><ul v-if="catalogList.length > 0"><li v-for="(item, index) in catalogList" :key="index" @click="changeVideoPlay(index)"><div class="catalog-list-title">{{item.sc_name}}</div></li></ul><div class="noLists" v-else>没有数据</div></div><!-- 分享 --><van-actionsheet v-model="shareSelect" title="分享" class="shareCh"><div class="bdsharebuttonbox bdshare-button-style0-32"><div class="shareline" @click='Qzshare'><a class="bds_qzone" data-cmd="qzone" href="javascript:;"></a><p>QQ空间</p></div><div class="shareline" @click='tsina'><a class="bds_tsina" data-cmd="tsina" href="javascript:;"></a><p>微博</p></div><div class="shareline" v-clipboard:copy="copyUrl" v-clipboard:success="onCopy" v-clipboard:error="onError"><a class="bds_copyurl" data-cmd="copyurl" href="javascript:;"></a><p>复制链接</p></div></div></van-actionsheet></div></transition> </template><script type="text/ecmascript-6">import {mapGetters}from 'vuex'import bdsharefrom 'bdshare'import { Toast }from 'vant'/*import 'common/js/aliplayer-h5-min.js'import 'common/js/json.min.js'*/exportdefault{props: {catalogList: {type: Array,default: () =>[]},lession: {},favorite:'',videoPlayIndex: {type: Number,default: 0},c_id: {type: Number,default: 0},videoplayShow: {type: Boolean,default: false}},data () {return{videoSrc:'',playTitle:'',classHour:0,voconShow:false,isCollect:false,scoreVal:5, //当前分值commentShow: false,AliUrl:'', //视频urlvid: '',playauth:'',shareSelect:false,noVideoPlayShow:false,passwordTip:'',ifShowPassword:false,copyUrl: window.location.href,submitIsCollection:true,s_id:'', //课时IDplayer: null,shareConfig: {bdText:this.$store.state.courseName,bdUrl:this.$store.state.bdUrl,bdPic:this.$store.state.bdPic}}},watch: {videoplayShow (val) {if (val === true) {this.classHour = this.catalogList.lengthif (this.catalogList.length > 0) {this.changeVideoPlay(this.videoPlayIndex)}}}},methods: {videoplayHidden () {this.voconShow = falsethis.$emit('videoHidden', false)},changeVideoPlay (index) {if (this.player) {this.player.dispose()var oSection = document.createElement('section')oSection.className= 'playBox prism-player videoplayIfram'oSection.id= 'AlivideoPlay'this.$refs.videoplay.appendChild(oSection)}this.videoOverdue(this.catalogList[index].id, index)},changeVocon () {this.voconShow = !this.voconShow},//收藏 collectionYes () {let _this= thisif (this.submitIsCollection) {this.submitIsCollection = false_this.axios({method:'post',url: _this.api.course.favorite,data: {cid:this.c_id,token: _this.api.token,client: _this.api.encodeClient}}).then(function (response) {if (response.status === 200 && response.data.states === true) {_this.$emit('changeFavorites', true)}_this.submitIsCollection= true}).catch(function (error) {console.log(error)_this.submitIsCollection= true})}},//取消收藏 collectionNo () {let _this= thisif (this.submitIsCollection) {_this.axios({method:'post',url: _this.api.course.unfavorite,data: {cid:this.c_id,token: _this.api.token,client: _this.api.encodeClient}}).then(function (response) {if (response.status === 200 && response.data.states === true) {_this.$emit('changeFavorites', true)}_this.submitIsCollection= true}).catch(function (error) {console.log(error)_this.submitIsCollection= true})}},//评分提交 commentSubmit () {let _this= this_this.axios({method:'post',url: _this.api.course.ajaxpinglunadd,data: {sec_score:this.scoreVal,s_id:this.s_id,c_id:this.c_id,token: _this.api.token,client: _this.api.encodeClient}}).then(function (response) {if (response.status === 200 && response.data.success === true) {_this.$toast('评分成功!')_this.evaluation= ''_this.commentConClose()}}).catch(function (error) {console.log(error)})},//打开评分弹出层 commentConShow () {this.commentShow = true},//关闭评分弹出层 commentConClose () {this.commentShow = false},shareopen () {this.shareSelect = true},Qzshare () {bdshare.qzone(this.shareConfig)},tsina () {bdshare.tsina(this.shareConfig)},//查看课程视频是否过期 videoOverdue (id, index) {let _this= this_this.axios({method:'get',url: _this.api.course.study,params: {id: id,token: _this.api.token,client: _this.api.encodeClient}}).then(function (response) {if (response.status === 200 && response.data.state === true) {_this.noVideoPlayShow= false_this.passwordTip=_this.catalogList[index].playpassif (_this.catalogList[index].videolocation === 'aliyun') {_this.ifShowPassword= false}else{_this.ifShowPassword= true}_this.AliUrl=response.data.data.lession.yun_url_this.playauth=response.data.data.lession.PlayAuth_this.playTitle=_this.catalogList[index].sc_name_this.s_id=_this.catalogList[index].id_this.aliyunPlay()}else{_this.noVideoPlayShow= true}}).catch(function (error) {console.log(error)})},onCopy (e) {this.shareSelect = falseToast('复制链接成功')},onError () {this.shareSelect = falseToast('复制链接失败')},aliyunPlay () {/*eslint-disable*/this.player = newAliplayer({id:'AlivideoPlay',width:'100%',height:'100%',vid :this.AliUrl,playauth :this.playauth,showBarTime:3000000,qualitySort:"asc"}, function (player) {//console.log("播放器创建成功"); });}},components: {...mapGetters(['courseName', 'bdUrl', 'bdPic'])}}</script><style scoped lang="less" rel="stylesheet/less" type="text/less">@import"../../common/less/variable";.videoplayback{position: absolute;z-index: 500;top:-90px;bottom:0;left:0;right:0;background-color: #f3f5f7;.videoPlayTop{position: relative;height: 90px;background-color: rgba(0, 0, 0, 0.7);.goBack{margin-left: 10px;width: 58px;height: 90px;vertical-align: middle;text-align: center;display: flex;justify-content:center;align-items:Center;float: left;.imgDiv{width: 18px;height: 30px;img{display: inline-block;float: left;width:100%;height:100%;}}}.passwordTip{position: absolute;left:50%;top:50%;transform: translate(-50%, -50%);color: #fff;font-size: 28px;}.videoOperation{width: 80px;height: 90px;float: right;margin-right: 10px;display: flex;justify-content:center;align-items:Center;.videoOperationImg{width: 30px;height: 6px;img{display: inline-block;float: left;width:100%;height:100%;}}}}.videoplay{width:100%;height: 420px;background-color: rgba(0, 0, 0, 0.7);position: relative;.videoplayIfram{width:100%;height: 420px;}.noVideoPlay{position: absolute;color: #fff;left:50%;top:50%;transform: translate(-50%, -50%);}}.videoOperationCon{position: absolute;background-color: #fff;border-radius: 4px;margin-top: 10px;top: 80px;right: 30px;display: flex;flex-direction: column;padding-bottom:26px;padding-right: 26px;padding-left: 26px;.voconItem{line-height: 28px;padding-top: 26px;&:first-child{padding-top: 22px;}.divImg{width: 30px;height: 28px;display: inline-block;img{vertical-align: top;width:100%;height:100%;}}.divVal{display: inline-block;font-size: @font-size-22;color: #313131;margin-left: 10px;}}}.commentShow{position:fixed;left:0;top:0;right:0;bottom:0;z-index: 500;background-color: rgba(0, 0, 0, 0.5);.commentCon{position: absolute;width:90%;padding-bottom: 50px;/*height: 200px;*/background-color: #fff;left:50%;top:50%;transform: translate(-50%, -50%);border: 1px solid #eeeeee;border-radius: 10px;.closeCommentCon{overflow: hidden;.commentConClose{float: right;padding: 10px;margin-right: 10px;.commentConCloseImg{width: 30px;height: 30px;img{width:100%;height:100%;}}}}.scroeRate{margin-top: 10px;}.commentSubmit{display: inline-block;padding: 5px 10px;color: #fff;font-size: @font-size-30;line-height: 40px;border-radius: 10px;background-color: #398ed1;margin-top: 30px;}}}.playTitle{color: #313131;font-size: @font-size-26;text-align: left;background-color: #fff;padding: 40px 30px;font-weight: bold;}.playDetails{padding: 20px 30px0;margin-top: 20px;background-color: #ffffff;overflow: hidden;.detailsPlay{border-bottom: 1px solid #dcdcdc;overflow: hidden;padding-bottom: 20px;.classHour{float: left;color: #313131;font-size: @font-size-22;}.goCourseDetail{float: right;color: #8a8a8a;font-size: @font-size-22;}}}.catalog-list{text-align: left;background-color: #fff;overflow: hidden;ul{overflow: hidden;padding: 10px030px;li{margin: 30px 30px0 0;line-height: 24px;overflow: hidden;.catalog-list-title{float: left;margin-left: 20px;color: #313131;font-size: @font-size-20;}}.on{.catalog-list-title{color: #398ed1;}}}.noLists{overflow: hidden;padding: 20px;font-size: @font-size-20;text-align: center;}}}.slide-enter-active,.slide-leave-active{transition: all .3s}.slide-enter,.slide-leave-to{transform: translate3d(100%, 0, 0)}.shareCh{overflow: hidden;.shareline{height: 120px;width: 150px;padding-top:36px;text-align:center;float: left;overflow: hidden;}.bdshare-button-style0-32a{height: 50px;width: 32px;display: block;margin:0auto;float: initial;}.bdshare-button-style0-32p{font-size: @font-size-24;}.bdshare-button-style0-32a.bds_qzone{background: url(http://static.crecgec.com/wxmobile/kongjian.png) 0 0 no-repeat;background-size: 100%auto;}.bdshare-button-style0-32 a.bds_tsina{background: url(http://static.crecgec.com/wxmobile/weibo.png) 0 0 no-repeat;background-size: 100%auto;}.bdshare-button-style0-32 a.bds_copyurl{background: url(http://static.crecgec.com/wxmobile/copyUrl.png) 0 0 no-repeat;background-size: 100%auto;}}</style>
demo地址下载
转载于:https://www.cnblogs.com/zhaobao1830/p/10006151.html
vue中引入js,然后new js里的方法相关推荐
- vue中引入高德js
项目概述: 通过在vue中引入高德js,实现地图的加载呈现,以及在地图中实现设备坐标定位,并在设备列表点击的同时进行定位点的切换和地图视图的切换,在点击坐标点的时候可以弹出相关介绍信息. 第一步:在i ...
- vue中引入全年日历插件calendar.js
针对依赖amazeui的全年日历插件在vue项目中的问题 cnpm i jquery cnpm i amazeui 在当前vue中引入jquery .amazeui及相关css或这全局引入(看其他是否 ...
- Vue中 引入使用 D3.js
Vue中 引入使用 D3.js 1. D3.js 学习文档 D3.js 中文网 D3.js 入门教程 D3.js v5版入门教程 d3.js API中文手册-[看云] d3.layout (布局)-[ ...
- 总结Vue中index.html、main.js、App.vue、index.js之间关系以及Vue项目加载流程
总结Vue中index.html.main.js.App.vue.index.js之间关系以及Vue项目加载流程 文章目录 总结Vue中index.html.main.js.App.vue.index ...
- vue项目引入标签云动画js函数,不执行
vue项目引入标签云动画js函数,数据重新渲染了,但是动画不执行了 rollTagCloud() {/* 3D标签云滚动函数*/const timer = setTimeout(() => {t ...
- Vue中引入echarts的步骤,折线图、柱状图、饼图的常用配置项
vue中引入echarts 一.安装echarts 二.引入echarts 1.全局引入 2.局部引入 三.vue中使用echarts 1.准备好函数 2.准备一个容器来放echarts 3.初始化容 ...
- Uniapp/Vue中引入使用阿里图标
一.uniapp中引入阿里图标 将图标加入购物车部分省略 1.下载阿里图标到本地,uniapp不支持symbol格式 2. 打开下载的压缩包,只需要inconfont.css ,将其放到我们的项目 s ...
- Vue中引入swiper插件报错:To install it, you can run: npm install --save swiper/css/swiper.css
Vue中引入swiper插件报错:To install it, you can run: npm install --save swiper/css/swiper.css 今天在写项目的时候用到了Sw ...
- Vue 中引入markdown富文本编辑器并根据md格式渲染
Vue 中引入markdown富文本编辑器 在vue组件中,比较好用的是mavon-editor,github文档地址 https://github.com/hinesboy/mavonEditor ...
- Vue中引入并使用动态图标
Vue中引入并使用动态图标 1.安装依赖 2.在Vue项main.js中引入 3.经过以上操作,已经实现全局引入,在任何地方直接使用即可. 本次选用Font-awesome-animation 1.安 ...
最新文章
- Python全栈开发day2
- 三关节机械臂控制需求说明压缩文件中的相关文档说明
- 【最新合集】IDEA 快捷键整理
- solidworks无法获得下列许可standard_SolidWorks2020安装无法获得下列许可SOLIDWORKS Standard怎么解决?...
- mysql 集群与主从_Mysql集群和主从
- redis 中一个字段 修改map_CTO 指名点姓让我带头冲锋,熬了一个通宵,终于把Redis中7千万个Key删完了...
- 飞鸽传书:服务器开发系列—系统构架
- java中常用的IO,你可否分得清、流的分类
- SBUS协议及编解码
- 《软件设计师教程最新版(第三版》
- 目不暇接!华为2020春季新品发布会群英荟萃
- google bert deeping watch
- 10、(十)外汇交易中专有名词整理
- No service of type FactoryLoggingManagerInternal available in ProjectScopeServices.
- windowsXP sp2 to sp3 的升级包
- R语言进入,提示都是日文怎么切换
- lrd热加载方式启动本地web服务(我用于从github把别人服务器代码拉倒本地去搭建自己的网络服务)
- C#中实现两个程序的通信
- 写CSDN文章时,生成下标、上标、竖线的方法
- STM32F103+SDIO wifi Marvell8801/Marvell88w8801 介绍(九) ---- Marvell 8801/Marvell 88w8801 实现AP功能/实现热点功能