vue使用本地json文件数据

static目录中新增res目录,

res目录中放入json文件

vue文件的mount或其他函数中调用axios.get

    this.axios.get(
      'static/res/address.json'
    ).then(res=>{
      console.log('get address')
      console.log(res.data)

      this.addressOptions = this.initAddress(res.data.root, 2)//自己处理json数据
    }).catch(error=>{
      console.log('get address error')
      console.log(error)
    })

npm run dev可用

npm run build之后上传到服务器也可用

猜你喜欢

转载自blog.csdn.net/youyudexiaowangzi/article/details/82468893