如何使用 Vue 專案在本地訪問我的 JSON 檔案?
我可以將它與一些外部鏈接一起使用(并且它有效):
mounted() {
this.loading = true;
axios.get("https://jsonplaceholder.typicode.com/todos").then((res) => {
this.posts = res.data;
this.loading = false;
this.sliceIt();
});
但我想把這個檔案(todos.json)暫時放到 src/assets/todos.json 并從那里使用它。
但這:
axios.get("http://localhost/assets/todos.json").then((res) => {
不起作用。
uj5u.com熱心網友回復:
您無法使用 axios 從自定義檔案夾中獲取資料。您應該使用靜態檔案夾來保存 todos.json 檔案。所以你應該把 axios 呼叫改成這樣:
axios.get("/static/todos.json")
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/376097.html
