wangguoyu 3 月之前
父節點
當前提交
a22c2553d8
共有 1 個文件被更改,包括 12 次插入1 次删除
  1. 12 1
      pages/newEnglish/components/xiangjie.vue

+ 12 - 1
pages/newEnglish/components/xiangjie.vue

@@ -15,7 +15,9 @@
 					<text class="details-title">实用口语</text>
 					<view  v-for="(item,index) in pageInfo.kouyu" :key="index" class="syky-content">
 						<view class="details-en-content">
-							<text>{{item.en}}</text>
+							
+							<rich-text :nodes="highlightWord(item.en)"></rich-text>
+						<!-- 	<text>{{item.en}}</text> -->
 							<!-- 变色  word-color-->
 							<!-- <text class="word-color">{{item.en}}</text>
 							<text>{{item.en}}</text> -->
@@ -55,6 +57,15 @@
 		getInfo(options)
 		data.value = options
 	})
+	const highlightWord = (text) => {
+		if (!text || !pageInfo.value.name){return text} 
+		const word = pageInfo.value.name;
+		const regex = new RegExp(word, 'gi');
+		console.log('pageInfo.value.name',pageInfo.value.name);
+		return text.replace(regex, (match) => {
+			return `<span style="color: #3a7fe9;">${match}</span>`;
+		});
+	}
 	const handleBack = () => {
 		uni.redirectTo({
 			url: `/pages/newEnglish/index?jieId=${data.value.jieId}&wordId=${data.value.wordId}`