const HISTORY_SEARCH_RECENT = "historysearchrecent"; export default { mounted() { if (window.localStorage.getItem([HISTORY_SEARCH_RECENT])) { try { this.historySearch = JSON.parse( window.localStorage.getItem([HISTORY_SEARCH_RECENT]) ); } catch (e) { window.localStorage.removeItem([HISTORY_SEARCH_RECENT]); } } }, methods: { initText(item) { this.textSearch = item; }, getHighlight(item) { var find = this.textSearch; var text = item.replaceAll(find, "" + find + ""); return text; }, selectHistorySearch(item) { this.textSearch = item; this.searchStart(this.textSearch); }, addHistorySearch(newSearch = "") { if (newSearch == "") { return; } var index = this.historySearch.indexOf(newSearch); if (index != -1) { this.historySearch.splice(index, 1); } this.historySearch.unshift(newSearch); this.saveHistorySearch(); }, removeHistorySearch(x) { this.historySearch.splice(x, 1); this.saveHistorySearch(); }, saveHistorySearch() { const parsed = JSON.stringify(this.historySearch); window.localStorage.setItem([HISTORY_SEARCH_RECENT], parsed); }, }, };