js imports json files

There are many ways to import json files, here is one method:
1. There are json files

insert image description here
File content
insert image description here
2. Upload to the server to get the url (you can also not upload it)
Get the url: "https://asc-test1.oss-cn-beijing.aliyuncs.com/2023/07/05/b1917481d4eb40628bc6d10113896d82taizhou.json"
or not Upload to the server, put the file directly into the project
3, call to
import axios

import axios from 'axios';

Called in the created method

created() {
    
    
  const service = axios.create({
    
    
				baseURL: 'https://asc-test1.oss-cn-beijing.aliyuncs.com/2023/07/05/', // 请求本地json文件,那么baseURL取空字符串,域名就会是项目域名
				timeout: 30000,
  });
  service.get('b1917481d4eb40628bc6d10113896d82taizhou.json').then(res => {
    
    
    console.log(res.data)
  })
},

Guess you like

Origin blog.csdn.net/qq_43840793/article/details/131549734