146146
147147<script lang="ts" setup>
148148import { codeToHtml } from " shiki"
149- import { computed , ref } from " vue"
149+ import { computed , onMounted , ref } from " vue"
150150import type { ProLangLanguage } from " @/types/main"
151151
152- const code = ref <string | null >(null )
153- const emits = defineEmits ([" select-lang" , " close" ])
154-
155152const props = defineProps <{
156153 lang: ProLangLanguage
157154 selectedLang: string | null
158155}>()
159156
160- const hasEnoughData = computed (() => {
161- return props . lang . link || props . lang . mainRepository
162- } )
157+ const code = ref < string | null >( null )
158+ const emits = defineEmits ([ " select- lang" , " close " ])
159+ const hasEnoughData = computed (() => props . lang . link || props . lang . mainRepository )
163160const castYears = JSON .parse (props .lang .years ).join (" , " )
164161
165162async function setCodeHtml(codeStr : string , lang ? : string ) {
@@ -173,19 +170,19 @@ async function setCodeHtml(codeStr: string, lang?: string) {
173170}
174171
175172async function showCode() {
176- if (code .value === null ) {
177- if (props .lang .rawCode ) {
178- await setCodeHtml (props .lang .rawCode )
179- } else if (props .lang .rawCodeLink ) {
180- const resp = await fetch (props .lang .rawCodeLink )
181- const text = await resp .text ()
182-
183- setCodeHtml (text )
184- }
185- }
186-
187173 emits (" select-lang" , props .lang .name )
188174}
175+
176+ onMounted (async () => {
177+ if (props .lang .rawCode ) {
178+ await setCodeHtml (props .lang .rawCode )
179+ } else if (props .lang .rawCodeLink ) {
180+ const resp = await fetch (props .lang .rawCodeLink )
181+ const text = await resp .text ()
182+
183+ setCodeHtml (text )
184+ }
185+ })
189186 </script >
190187
191188<style lang="scss" scoped>
0 commit comments