errorCaptured(err, vm, info) { // err: error trace // vm: component in which error occured // info: Vue specific error information such as lifecycle hooks, events etc. // TODO: Perform any custom logic or log to server }, };
Logic Error Sample
以 Demo site 為例子 我們故意在 method 裡面加入兩個 JSON Parse 的錯誤
chunk-vendors.f74a5e6c.js:1SyntaxError: Unexpected token D inJSON at position 0 at JSON.parse (<anonymous>) at Proxy.jsError (validate.942ffcee.js:1:51528) at onClick.t.<computed>.t.<computed> (validate.942ffcee.js:1:50549) at vh (chunk-vendors.f74a5e6c.js:1:228008) at u (chunk-vendors.f74a5e6c.js:1:354212) at h (chunk-vendors.f74a5e6c.js:1:27792) at f (chunk-vendors.f74a5e6c.js:1:27875) at HTMLButtonElement.n (chunk-vendors.f74a5e6c.js:1:71846)
先假設我們後端有收到錯誤 LOG
我們就可以先透過 Source map cli decrypt 錯誤的行數
重點是下面這行錯誤代碼 告訴你是哪一隻檔案&資訊
1
validate.942ffcee.js:1:51528
我們就可以透過 source map 解開後知道在哪邊有噴錯
1 2 3 4
D:\vue\vue_menu\dist\js>source-map resolve validate.9cc0683f.js.map 1 51528 Maps to webpack://vue_menu/src/views/ErrorSample.vue:70:32 (parse)