我有一个使用vue方式编写的html文件,我想要在一个vue文件中引入并渲染该文件,直接读取该文件并使用v-html赋值后并不能正常生成
<template>
<div>
<div v-html="innerHTML"></div>
</div>
</template>
<script setup lang="ts">
import { onMounted, ref } from 'vue'
const innerHTML = ref()
onMounted(() => {
getVersion()
})
function getVersion() {
var xhr = new XMLHttpRequest();
xhr.open("get", 'doc.html', true);
xhr.onreadystatechange = function (data) {
if (xhr.readyState == 4 && xhr.status === 200) {
innerHTML.value = xhr.responseText;
}
}
xhr.send()
}
</script>
<style scoped lang="scss">
</style>
请问我该怎么处理?
此时你有两个选择:
import()
动态加载组件。这需要你在开发时就决定好有哪些组件可能会被加载进来。