不支持

vue3 搜索关键字变颜色

let inputNews = ref('')
let element = ref('')
const seachNews = (contentText) => {
    for (let j = 0; j < contentText.length; j++) {
        element = contentText[j];
        // 刷新列表数据
        let res = element.title
        if (inputNews.value == '') {
            return res;
        } else {
            let wordsArray = res.split('');
            for (var i = 0; i < wordsArray.length; i++) {
                if (inputNews.value.includes(wordsArray[i])) {
                    wordsArray[i] = "<span style='color: red;'>" + wordsArray[i] + '</span>';
                }
            }
            res = wordsArray.join('');
            console.log(res)
            contentText[j].title = res
            console.log(contentText)
        }

    }
}

 

posted @ 2024-01-02 15:49  骑上我的小摩托  阅读(132)  评论(0编辑  收藏  举报