json添加注释的方法

js yekong 678℃

前端vue项目开发时,客户要求自己修改json文件里的值,这时就需要在json添加注释以便于客户可以看明白哪些值是怎么对应的。

{
  "//": "只在登录时读取并缓存",
  "home1": {},
  "home2": {},
  "home3": {
    "?item1": "项目概况",
    "item1": 10
  }
}

获取json值

getJson() {
  axios.get('/dingshi.json')
    .then(function (response) {
      console.log(response.data)
      // 处理成功情况
      console.log(response);
    })
    .catch(function (error) {
      // 处理错误情况
      console.log(error);
    })
    .then(function () {
      // 总是会执行
    });
},
喜欢 (0)