使用Vuejs读取本地JSON文件吗?

时间:2018-08-17 13:05:02

标签: javascript vue.js readfile

如何使用Vuejs读取本地json文件? 这是我的简单JSON文件:

(someJSON.json)

[
  {
    "id": 6,
    "description": "Dafgard project backup",
    "name": "Dafgard",
    "avatar_url": null,
    "commit_count": 0,
    "last_activity_at": 1418820265000
  },
  {
    "id": 11,
    "description": "dafgard.net repo",
    "name": "dafgardDotNet",
    "avatar_url": null,
    "commit_count": 0,
    "last_activity_at": 1441780268000
  }

现在,当我启动带有响应的tomcat服务器时,我读取了此文件

<script>
export default {
        created: function() {
            this.refreshProjects()
        })
    },
    methods: {
       refreshProjects() {
          console.log(this)
           let vm = this
            // http://localhost:8080
            fetch('/Teamify/Testing/api/some').then((response) => response.json()).then(json => {
            => response.json()).then(json => {
                vm.projects = json
            })
        }
    }
}
</script>

所以,我想在本地读取此文件。

如果有人帮助我编写一些代码,我会很高兴的:)

0 个答案:

没有答案