把多语言json转化为多个JSON文件

dowFile (item) {
      const data = { translate: json[item] }
      let blob = new Blob([JSON.stringify(data)], { type: 'text/plain' });
      let file = new File([blob], `${item}.json`, { type: 'text/plain' });
      let a = document.createElement('a');
      let downUrl = window.URL.createObjectURL(file);
      let filename = `${item}.json`;
      a.href = downUrl;
      a.download = filename;
      a.click();
      console.log(Object.keys(json).length)
      delete json[item]
      setTimeout(() => {
        if (Object.keys(json).length > 0) {
          this.dowFile(Object.keys(json)[0])
        }
      }, 200)
    },
this.dowFile('vzh_rCN')//vzh_rCN是json里第一个语言的属性名,表示从第一个语言开始

 

posted @ 2022-03-03 14:16  chicidol  阅读(79)  评论(0编辑  收藏  举报