1.将json数据放到public文件(public文件和src同级);

2.页面中使用如下

const defaultData = ref({}); // 接收json数据
const getDefaultData = () => {
  fetch(process.env.BASE_URL + '/test.json') // public/test.json 文件
    .then((response) => response.json())
    .then((res) => {    
      defaultData.value = { ...res };
    })
    .catch((error) => console.error('加载失败:', error));
};
onBeforeMount(() => {
  getDefaultData();
});

Logo

Agent 垂直技术社区,欢迎活跃、内容共建。

更多推荐