vue 3 0中使用本地的json檔案

2021-09-24 10:50:31 字數 580 閱讀 8214

1.main.js檔案中

import axios from 'axios';

axios.get('/api/city').then(data => {

console.log(data);

/api/city是根據自己的檔案設定的。

2.vue.config.js

const express = require('express');

var city = require('./public/city.json');//此處位置一定要書寫正確。看清是./還是/。

var apiroutes = express.router();

devserver: {

res.json({

errno: 0, // 這裡是你的json內容

data: city,

3.訪問http://localhost:8080/api/city即可訪問到json的檔案

重點:vue cli3.0 public 資料夾才是靜態資源檔案。修改配置檔案之後一定要重啟專案。

六月十三號。

vue3 0中使用web雲開發(2)

這一篇說一下雲資料庫的使用 資料庫的基本操作 資料的新增 db.collection test add then res 讀取資料庫中資料 db.collection test doc 該條資料的id get then res 根據條件查詢 更新資料 db.collection test doc 該...

Vue中使用本地json資料

專案中有有乙個地區介面,伺服器原因請求速度很慢很慢,於是考慮將地區介面的資料設定為本地的json檔案。大大提公升請求速度 一 首先建立乙個json檔案,將資料放進去,一定要確保格式正確我的是這樣的,把json檔案放在static資料夾下,放到static資料夾下 二 像使用axios一樣去呼叫jso...

Vue3 0系列(Vue3 0是如何變快的 )

來說一說為什麼performance 效能比vue 2.x快1.2 2倍 這裡先提供兩個 2.1 diff演算法優化 例子 我是段落 也就是說,vue3在渲染的時候,給會改變的元素新增了靜態標記 import from vue export function render ctx,cache,pro...