将以HTML格式保存的图片显示到Vue.js页面中

2024-10-01 00:24:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前正试图在我的Vue.js页面中显示以HTML格式保存的本地图片。 我尝试使用以下行将HTML文件的内容加载到变量中:

computed: {
    compiledHtml: function() {
      return this.asset;
    }
      const path = 'http://localhost:5000/load_results'
      axios
        .get(path)
        .then((res) => {
          this.asset = res.data
        })

然后我尝试使用v-html显示它: <div v-html="compiledHtml"></div>

它实际上与包含几行的简单HTML文件一起工作,例如: <h1> test load HTML file </h1>

但是,我的图片大小是3.5Mb,比我给你的示例复杂得多,当我试图显示它时,它会给我一个空白

有人知道如何克服这个问题吗?谢谢

下面是我使用的GET方法:

@bp.route('/load_results', methods=['GET'])
def load():
    f = codecs.open("./file.html", 'r', 'utf-8')
    return f.read()

Tags: 文件pathdivgetreturnhtmlloadres
1条回答
网友
1楼 · 发布于 2024-10-01 00:24:50

我通过修改GET方法在API中打开文件成功地解决了这个问题,如下所示:

import webbrowser

@bp.route('/load_html_picture_file', methods=['GET'])
def load():
    webbrowser.open(path_to_file)

因此,它会在我的webbrowser中的新选项卡中打开我的图像。 无论如何,谢谢你

相关问题 更多 >