Skip to content

Commit 2dfdd83

Browse files
Jinjiangktsn
authored andcommitted
docs: replaced video preview code to a VideoPreview component (#1453)
* replaced video preview code to a VideoPreview component * docs: dropped v-if/v-else way to fix video autoplay issue on Chrome
1 parent c92cef3 commit 2dfdd83

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<template>
2+
<a href="#" @click.prevent="open">
3+
<img :src="img" :alt="title" style="border-radius: 6px;">
4+
</a>
5+
</template>
6+
7+
<script>
8+
export default {
9+
props: {
10+
title: {
11+
type: String,
12+
default: "Play Vuex Explained Visually Video"
13+
},
14+
img: {
15+
type: String,
16+
default: "/vuex-explained-visually.png"
17+
},
18+
url: {
19+
type: String,
20+
default: "https://player.vimeo.com/video/297515936?autoplay=1"
21+
}
22+
},
23+
methods: {
24+
open() {
25+
// dropped v-if/v-else way to fix autoplay issue on Chrome
26+
// https://github.com/vuejs/vuex/pull/1453#issuecomment-441507095
27+
const { $el, url } = this;
28+
if (!$el || !$el.parentNode) {
29+
return;
30+
}
31+
const attrs = {
32+
width: 640,
33+
height: 360,
34+
frameborder: 0,
35+
src: url,
36+
webkitallowfullscreen: true,
37+
mozallowfullscreen: true,
38+
allowfullscreen: true
39+
};
40+
const video = document.createElement('iframe');
41+
for (const name in attrs) {
42+
video.setAttribute(name, attrs[name]);
43+
}
44+
$el.parentNode.replaceChild(video, $el);
45+
}
46+
}
47+
}
48+
</script>

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# What is Vuex?
22

3-
<a id="vuex-video-preview" href="javascript:var vuexVideoPreviewEl = document.getElementById('vuex-video-preview'); var videoWrapperEl = document.createElement('div'); videoWrapperEl.innerHTML = '<iframe src=&quot;https://player.vimeo.com/video/297515936?autoplay=1&quot; width=&quot;640&quot; height=&quot;360&quot; frameborder=&quot;0&quot; webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>'; vuexVideoPreviewEl.parentNode.insertBefore(videoWrapperEl, vuexVideoPreviewEl); vuexVideoPreviewEl.parentNode.removeChild(vuexVideoPreviewEl)"><img src="/vuex-explained-visually.png" alt="Play Vuex Explained Visually Video" style="border-radius: 6px;"></a>
3+
<VideoPreview />
44

55
Vuex is a **state management pattern + library** for Vue.js applications. It serves as a centralized store for all the components in an application, with rules ensuring that the state can only be mutated in a predictable fashion. It also integrates with Vue's official [devtools extension](https://github.com/vuejs/vue-devtools) to provide advanced features such as zero-config time-travel debugging and state snapshot export / import.
66

0 commit comments

Comments
 (0)