diff --git a/src/views/Compare/Dashboard/Compare.vue b/src/views/Compare/Dashboard/Compare.vue index 91df11b..780273c 100644 --- a/src/views/Compare/Dashboard/Compare.vue +++ b/src/views/Compare/Dashboard/Compare.vue @@ -9,9 +9,8 @@

{{ i18next.t("Compare.timeUsage") }}

@@ -19,10 +18,9 @@

{{ i18next.t("Compare.frequency") }}

@@ -263,6 +261,24 @@ export default { } }, methods: { + handleClick(tagId) { + this.isActive = tagId; + + // 在進行導航前,檢查或處理 tagId 的值 + if (this.isSafeTagId(tagId)) { + window.location.href = tagId; // 確保這個路徑是安全的 + // 或者使用 Vue Router 進行導航 + // this.$router.push({ path: tagId }); + } else { + console.warn("不安全的 tagId: ", tagId); + } + }, + // 避免直接使用動態 href:改用安全的方法來處理動態導航,避免直接將未經驗證的數據綁定到 href 屬性。 + isSafeTagId(tagId) { + // 檢查 tagId 是否符合安全的格式(例如只允許特定的模式或路徑) + const pattern = /^#?[a-zA-Z0-9-_\/]*$/; // 例如: #waitingTime + return pattern.test(tagId); + }, /** * 手刻折線圖 x label 時間刻度 * @param { object } valueData {min: '2022-02-20T19:54:12', max: '2023-11-27T07:21:53'}