根据URL路径获取JSON数据

背景

后端接口返回的是http://*****.json 路径,项目需要使用基于Vue3的vue-json-viewer@3预览JSON数据。所以需要通过URL路径获取JSON数据,浏览器直接访问JSON URL 默认是下载到本地(行不通)

通过URL获取JSON数据如下:

fetch(jsonUrl)
        .then(response => response.json())
        .then(jsonData => {
    
    
            // jsonData 是对象
            console.log('json数据是:'+jsonData);
        });

猜你喜欢

转载自blog.csdn.net/weixin_44224921/article/details/128471326