Vue 调用本地的 json 文件

Vue 用 axios 调用本地的 json 文件,json 必须存放在 “ static ” 文件夹下,static 目录是 vue-cli 向外暴露的静态文件夹,所有静态数据都应该放到static目录中。

如下图所示:
这里写图片描述

在调用时,如下,其实地址就是 http://localhost:800x/static/tabs.json

this.$fetch('static/tabs.json').then(response => {
    console.log(response)
    this.editableTabs = response.data
    this.tabIndex = this.editableTabs.length
}).catch(err => {
    console.log(err)
})

你可能感兴趣的:(Vuejs)