第一种:
在 public 文件夹下创建 jsonTest.JSON
JSON 格式的数据如下:
- {
- "innerList": [
- {"attr1":"内部数据 1","attr2":"内部数据 2",...},
- {"attr1":"内部数据 1","attr2":"内部数据 2",...},
- ....
- ]
- }
在某一组件内:
......html 元素
- import people from '../../json/jsonTest.json';
- export default{
- data(){
- return {
- dataset: people.innerList
- }
- }
- }
第二种:
- getDataList(){
- this.$axios.get("/json/jsonTest.json").then((res)=>{
- // 得到 response.data 数据做具体赋值操作
- }).catch(() => {
- response.errer
- this.$message({
- message: response.errer.msg
- })
- })
来源: http://www.bubuko.com/infodetail-3402194.html