提交 916d5dc3 编写于 作者: View Design's avatar View Design

Update ProsePre.global.vue

上级 3e2c491e
...@@ -10,13 +10,14 @@ ...@@ -10,13 +10,14 @@
/> />
</pre> </pre>
<UDivider :ui="{ border: { base: 'border-gray-700' } }" /> <UDivider :ui="{ border: { base: 'border-gray-700' } }" />
<pre :class="$props.class" class="m-0 rounded-tl-none rounded-tr-none"><slot /></pre> <pre :class="$props.class" class="m-0 rounded-tl-none rounded-tr-none"><code ref="codeBlock">{{ code }}</code></pre>
</div> </div>
</template> </template>
<script setup> <script setup>
import hljs from 'highlight.js'
import 'highlight.js/styles/github-dark.css'
const toast = useToast() const toast = useToast()
const slots = useSlots()
const props = defineProps({ const props = defineProps({
code: { code: {
type: String, type: String,
...@@ -54,14 +55,16 @@ const handleCopy = () => { ...@@ -54,14 +55,16 @@ const handleCopy = () => {
title: '复制成功' title: '复制成功'
}) })
} }
watch( const codeBlock = ref(null)
() => slots.default(), const handleRender = () => {
(newValue, oldValue) => { if (codeBlock.value) {
// 在这里处理默认插槽内容的变化 codeBlock.value.textContent = props.code
console.log('Default slot content changed:', newValue) hljs.highlightElement(codeBlock.value)
}, }
{ immediate: true, deep: true } }
) onMounted(() => {
handleRender()
})
</script> </script>
<style> <style>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册