vue1.0本地引入Json文件

先说说遇到的坑吧,之前是用2.0开发,都是用import方式引入文件;(注: json文件跟我的页面是同级 )

方法1:import  jsonData from 'map.json'      //vue2.0常用的就是这种方式引入
      //运行结果:报错 Uncaught SyntaxError: Unexpected identifier

方法2:const jsonData =require('map.json');      //require引入
      //运行结果:报错 Uncaught ReferenceError: require is not defined

前面两个方法都报错,然后尝试下面的方式,成功拿到数据

方法3:this.$http.get('map.json').then(response => {   
            console.log(response)
      }, response => {
            console.log('数据加载失败')
      })

猜你喜欢

转载自blog.csdn.net/qq_41806475/article/details/84638391