vue 将json数据打包到dist(方便json在打包后修改其内容)
·
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();
});
更多推荐

所有评论(0)