<template>
<div id="app">
<d-player ref="player" id="player" :options="options"></d-player>
</div>
</template>
<script>
export default {
data() {
return {
name:'my.mp4',
options: {
container: document.getElementById("dplayer"), //播放器容器
mutex: false, // 防止同时播放多个用户,在该用户开始播放时暂停其他用户
theme: "#b7daff", // 风格颜色,例如播放条,音量条的颜色
loop: false, // 是否自动循环
lang: "zh-cn", // 语言,'en', 'zh-cn', 'zh-tw'
screenshot: true, // 是否允许截图(按钮),点击可以自动将截图下载到本地
hotkey: true, // 是否支持热键,调节音量,播放,暂停等
preload: "auto", // 自动预加载
volume: 0.7, // 初始化音量
playbackSpeed: [0.5, 0.75, 1, 1.25, 1.5, 2, 3], //可选的播放速度,可自定义
video: {
url:'./video/my.mp4'
}},
}
},
}
</script>
<style lang="less">
.dplayer{
width: 500px;
height: 300px;
}
</style>
this.options.video.url = '你的视频路径'
options
中没有视频链接,之后设置视频链接时,直接通过 this.options.video.url = videoPath
是无效的this.$refs.player.dp
,然后通过 switchVideo()
对 url
进行修改<template>
<d-player ref="player" :options="options"></d-player>
</template>
<script type="text/ecmascript-6">
import dPlayer from 'vue-dplayer'
import 'vue-dplayer/dist/vue-dplayer.css'
export default {
name: 'in-video',
props: {
source: {
type: String,
default: ''
}
},
data () {
return {
player: null,
options: {
video: {
url: ''
},
contextmenu: [
{}
]
}
}
},
mounted() {
this.player = this.$refs.player.dp
},
created() {
this._setVideoUrl(this.source)
},
methods: {
// 设置视频播放路径
_setVideoUrl (url) {
this.player.switchVideo({
url: url
})
}
},
components: {
dPlayer
}
}
</script>
根据参考资料和问题要求,以下是解决方案:
配置路由:
routes:[
{ path: '/detail/:url', component: Detail }
]
在跳转页面时传递值:
<router-link :to="'/detail/' + url">跳转到详情页面</router-link>
在对应页面获取值并使用:
created() {
this.url = this.$route.params.url;
}
在模板中引入静态资源示例:
<template>
<div>
<img src="/resource/img/pic1.png" alt="" />
<img src="resource/img/pic1.png" alt="" />
</div>
</template>
使用this.$router.push()方法修改URL参数:
this.$router.push(`${this.$route.path}?url=${newUrl}`);
或者使用webpack-merge插件修改URL参数:
import merge from 'webpack-merge';
this.$router.push({
query: merge(this.$route.query, { 'url': newUrl })
});
使用replaceState方法替换URL:
let newUrl = window.location.href.replace(/&?url=[^&]*/g, '');
window.history.replaceState(null, null, newUrl);
将图片引入为模块:
require('../assets/logo.png');
创建一个Image对象,设置图片地址,并在onload事件中获取图片的宽度和高度:
let img = new Image();
img.src = "http://example.com/image.jpg";
img.onload = function() {
let width = img.width;
let height = img.height;
console.log(width, height);
};
使用encodeURIComponent编码URL参数:
let encodedUrl = encodeURIComponent(url);
以上是解决问题的具体步骤和代码示例,如果您还有其他问题,请随时向我提问。