close

1.編譯工具使用VScode

在資料夾準備一份setting.json 設定檔案

內容

 

{ "liveServer.settings.port": 8080, "liveServer.settings.ignoreFiles": [ ".vscode/**", "**/*.scss", "**/*.sass", "**/*.ts", "**/*.json" ] }

ps. port: 8080 (通訊錄的網頁port)

 

2.安裝node.js 

到node.js網站下載安裝檔並安裝

安裝完畢後,到終端機打上指令, Node專案初始化指令 " npm init "

 

3.安裝node.js中的 json-server

用終端機打上安裝指令 " npm i json-server "

ps. i = install 安裝

 

4.製作一個資料庫( 使用json充當 )

新增一個 db.json ,( db : 自己取的檔名 )

先自己手動刻上一筆資料

{
"contact": [
{
"id": 1,
"name": "ABC",
"email": "abc@abc.com"
},
  ]
}

 

5. 設定npm指令 

剛才步驟2,初始化完畢後,資料夾內會有一份package.json檔,打開找到 "script" ,會有一個系統設置好的指令 "test" 指令

新增 "json" :"json-server --watch db.json --port 8888" 

ps. "json" : 自定義指令名稱 , json-server : nodejs套件名稱, db.json : 步驟4充當資料庫的 json檔 , --port 8888 : 資料庫的port

 

6.啟動資料庫 指令

到終端機打上指令 npm run json ( 每次重開機,都要啟動)

 

HTML檔 https://codepen.io/cdpro2/pen/KbZWQX

arrow
arrow
    文章標籤
    html javescript vue js
    全站熱搜

    Aha 發表在 痞客邦 留言(0) 人氣()