【问题标题】:Read file using in vue template使用 vue 模板读取文件
【发布时间】:2020-01-20 11:32:37
【问题描述】:

我需要使用vue.js从系统中读取文件
比如:

import fs from "fs"; 
var fs = require("fs"); 

fs.readFile("path");

我在导入 fs 时出错。我做错了什么?

【问题讨论】:

  • 请分享您遇到的错误,以便我们为您提供帮助
  • 不清楚你想做什么。您希望您的 Vue 应用程序读取存在于用户计算中的文件吗?或者您想读取服务器中的文件?

标签: node.js vue.js fs


【解决方案1】:

我为此目的使用Axios

axios.get('/' + 'settings.json').then(response => {
     console.log(response.data);
     //do anything you want with response.data (content of the file)
})

您的文件必须位于public 文件夹中

【讨论】:

    猜你喜欢
    • 2011-07-05
    • 1970-01-01
    • 2021-06-08
    • 1970-01-01
    • 1970-01-01
    • 2021-12-28
    • 1970-01-01
    • 2016-03-19
    • 2019-09-22
    相关资源
    最近更新 更多