在vuejs页面中通过axios获取本地static文件夹下的json文件
vue cli3.0访问本地JSON文件
在vue-cli3中使用axios获取本地json
我最终采用了这个办法:
element-ui table 页面加载时,动态渲染后台传过来的数据(springmvc)
甚至有可能会出现这个bug
TypeError: props.sections.reduce is not a function
在我的项目中,json文件是一定要放到public文件夹中的:
关键代码部分:
链接axios导入elementui+table数据的部分
import axios from "axios";
export default {
data(){
tableData: [],
}
mounted() {
let _this =this;
axios.get('./Proweekly.json').then((res)=>{
console.log(res.data.tableData);
console.log(_this.tableData);
_this.tableData = res.data.tableData;
})
.catch(function(error){
console.log(error);
})
}
}
值得一提的是:
也可以在main.js文件中写入下面的代码:
import axios from 'axios';
axios.get('./Proweekly.json').then((data)=>{
console.log(data.data);
})
完整代码在这里~可以不用看 哈
<template>
<el-main>
<el-row>
<el-col :span="6">