Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e9a009b

Browse files
Merge pull request #1 from bsrsnlbyrk/master
default embed code added for useEmbed example
2 parents ea58abc + 265709b commit e9a009b

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

‎example/vue3/src/components/useEmbed.vue‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
<script setup lang="ts">
2-
import { ref } from 'vue';
3-
import { useEmbed } from 'vue3-use-hooks';
4-
const code = ref(null);
2+
import { ref } from "vue";
3+
import { useEmbed } from "vue3-use-hooks";
4+
import exampleEmbed from "../shared/exampleEmbed";
5+
6+
const code = ref(exampleEmbed);
57
const { isEmbedBlock, clear } = useEmbed(code);
68
</script>
79

810
<template>
911
<div class="example-container">
1012
<div class="flex-container">
11-
<textarea rows="5" cols="50" placeholder="Place embed code here" v-model="code"></textarea>
13+
<textarea
14+
rows="5"
15+
cols="50"
16+
placeholder="Place embed code here"
17+
v-model="code"
18+
></textarea>
1219
<button type="button" class="clear-button" @click="clear">Clear</button>
1320
</div>
1421
<div v-if="isEmbedBlock" v-html="code" class="embed-block"></div>
@@ -52,4 +59,4 @@ $white: #fff;
5259
margin-bottom: 2em;
5360
}
5461
}
55-
</style>
62+
</style>

‎example/vue3/src/shared/exampleEmbed.js‎

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/useEmbed.ts‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ref, computed, watch, Ref } from 'vue';
1+
import { ref, computed, watch, Ref,onMounted } from 'vue';
22

33
declare global {
44
interface Window {
@@ -78,10 +78,15 @@ const useEmbed = (code: any = null) => {
7878
injectedScripts.value = [];
7979
};
8080

81+
onMounted(() => {
82+
if (embedCode.value) {
83+
injectScript({ id: 'id', src: getEmbedScriptSrc(embedCode.value) });
84+
}
85+
})
86+
8187
watch(code, newValue => {
8288
if (newValue) {
83-
const src = getEmbedScriptSrc(newValue);
84-
injectScript({ id: 'id', src });
89+
injectScript({ id: 'id', src: getEmbedScriptSrc(newValue) });
8590
}
8691
});
8792

@@ -91,4 +96,4 @@ const useEmbed = (code: any = null) => {
9196
};
9297
};
9398

94-
export default useEmbed;
99+
export default useEmbed;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /