xuyonghao
2024-11-27 db2339e341668d14506c114ee88d6d143d4813b0
src/views/dmx/knowledgeLib/components/txt.vue
@@ -1,6 +1,6 @@
<template>
  <div>
    <pre v-html="content"></pre>
    <pre v-text="content"></pre>
  </div>
</template>
@@ -8,6 +8,7 @@
import { ref, watch } from "vue";
let content = ref("");
//   获取父组件传递的资源url
const props = defineProps({
  previewSrc: {
@@ -17,14 +18,30 @@
  }
});
const getContent = (url) => {
  fetch(url)
    .then((res) => res.text())
    .then((data) => {
      content.value = data;
    });
//监控属性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(props.previewSrc);
getContent();
const comStyle = {