<template>
|
<div>
|
<pre v-text="content"></pre>
|
</div>
|
</template>
|
|
<script setup>
|
import { ref, watch } from "vue";
|
|
let content = ref("");
|
|
// 获取父组件传递的资源url
|
const props = defineProps({
|
previewSrc: {
|
type: String,
|
required: false,
|
default: () => ""
|
}
|
});
|
|
//监控属性previewSrc的变化,如果发生变化,重新获取内容
|
watch(
|
() => props.previewSrc,
|
() => {
|
getContent();
|
}
|
);
|
|
const getContent = () => {
|
content.value="";
|
fetch(props.previewSrc, {
|
responseType: "arraybuffer"
|
}).then(
|
(response) => {
|
return response.arrayBuffer();
|
}
|
).then(
|
(data) => {
|
const decoder = new TextDecoder('gbk');
|
content.value = decoder.decode(data);
|
}
|
);
|
};
|
getContent();
|
|
|
const comStyle = {
|
width: "100%",
|
height: "100%"
|
};
|
|
const renderedHandler = () => {
|
console.log("rendered");
|
};
|
const errorHandler = (err) => {
|
console.log("error", err);
|
};
|
</script>
|
|
<style scoped lang="less">
|
.aUpload {
|
position: absolute;
|
top: 0;
|
left: 0;
|
}
|
</style>
|