<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當(dāng)前位置: 首頁 - 科技 - 知識百科 - 正文

        Vue實(shí)現(xiàn)搜索結(jié)果高亮顯示關(guān)鍵字

        來源:懂視網(wǎng) 責(zé)編:小OO 時(shí)間:2020-11-27 21:55:57
        文檔

        Vue實(shí)現(xiàn)搜索結(jié)果高亮顯示關(guān)鍵字

        本文實(shí)例為大家分享了Vue實(shí)現(xiàn)搜索結(jié)果高亮顯示關(guān)鍵字的具體代碼,供大家參考,具體內(nèi)容如下:1.需要解決的問題 父組件將搜索的字段傳到子組件 子組件接受數(shù)據(jù),正則匹配,并替換字段。2.具體代碼;父組件代碼;
        推薦度:
        導(dǎo)讀本文實(shí)例為大家分享了Vue實(shí)現(xiàn)搜索結(jié)果高亮顯示關(guān)鍵字的具體代碼,供大家參考,具體內(nèi)容如下:1.需要解決的問題 父組件將搜索的字段傳到子組件 子組件接受數(shù)據(jù),正則匹配,并替換字段。2.具體代碼;父組件代碼;

        本文實(shí)例為大家分享了Vue實(shí)現(xiàn)搜索結(jié)果高亮顯示關(guān)鍵字的具體代碼,供大家參考,具體內(nèi)容如下

        1. 需要解決的問題

      1. 父組件將搜索的字段傳到子組件
      2. 子組件接受數(shù)據(jù),正則匹配,并替換字段
      3. 2. 具體代碼

        父組件代碼

        <template>
         <div>
         <div v-if="showMe">
         <div class="re_search">
         <svg @click="$router.go(-1)">
         <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#arrow-left.6f6409e" rel="external nofollow" ></use>
         </svg>
         <input type="search" v-model="search_text" class="v-md" placeholder="請輸入商品名稱" @keydown.enter="search_method">
         </div>
         <OneBusiness v-for="(item, n) in search_res" :key="n" :item="item" :search_text="search_text"></OneBusiness>
         </div>
         <!--<!– 撐開Fixednav擋住的位置 –>-->
         <div class="space"></div>
         <!-- 固定導(dǎo)航欄 -->
         </div>
        </template>
        
        <script>
        import { mapGetters } from 'vuex';
        import OneBusiness from './small_components/One_business';
        import {getSearchData} from 'src/service/getData'
        
        
        export default {
         name: 'search',
         data () {
         return {
         showMe: false,
         search_text: '', // 搜索框內(nèi)容
         search_res: [] // 搜索結(jié)果
         };
         },
         mounted () {
         this.$store.dispatch('setLoading', true);
         // 模擬加載
         var time = Math.floor(Math.random() * 2000);
         console.log('模擬加載用時(shí)' + time);
         setTimeout(() => {
         this.$store.dispatch('setLoading', false);
         this.showMe = true;
         }, time);
         this.search_method();
         },
         computed: {
         ...mapGetters([
         'getFalseBussinessbrief' // 商家簡略信息
         ])
         },
         methods: {
         async search_method () {
        
         var mainWord = this.$route.params.keyword;
         if (this.search_text !== '' && this.search_text !== this.$route.params.keyword) {
         mainWord = this.search_text;
         }
         this.search_text = mainWord;
         this.search_res = (await getSearchData(this.search_text)).obj.results;
         console.log(this.search_res);
         }
         },
         components: {
         OneBusiness
         }
        };
        </script>
        
        <style lang="less" scoped>
        .re_search{
         background:#0096ff;
         line-height:0;
         padding: .2rem;
         svg{
         width:.6rem;
         height:.6rem;
         }
         input[type="search"]{
         display:inline-block;
         height:.9rem;
         width:8rem;
         outline: none;
         border: none;
         border-radius:.45rem;
         background:#f2f2f2;
         box-sizing: border-box;
         padding: 0 .5rem;
         font-size:.4rem;
         }
        }
        </style>

        子組件代碼

        <template>
         <!-- 列表單個(gè)商家 -->
         <section class="tj_business" >
         <section class="one_business clear">
         <div class="business_img">
         <img src="../../images/guozhao.png" alt="">
         </div>
         <div class="business_info">
         <section class="business_name clear">
         <router-link :to="'/business/' + item.classNum">
         <h3 class="fl ell"><span v-if="item.className">大類</span>第{{item.classNum}}類{{ item.className }}</h3>
         </router-link>
         <div class="name_icon fr">
         <div class="code_num fr">
         <svg @click="add_cart(item.id)" style=" width: .5rem; height: .5rem;">
         <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#cart-minus" rel="external nofollow" ></use>
         </svg>
         </div>
         </div>
         </section>
         <section class="business_code clear">
         <div class="code_num fl">
         <!--<svg class="v-md">-->
         <!--<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#rating-star" rel="external nofollow" ></use>-->
         <!--</svg>-->
         <span class="v-md">【{{item.parentNum}}組】{{ item.groupName }}</span>
         </div>
         <div class="code_icon fr">
         </div>
         </section>
         <section class="business_other clear">
         <div class="other_price fl">
         <span class="com_gray1" v-html="ruleTitle"></span>
         <span>/</span>
         <span class="com_gray1">{{ item.number }}</span>
         </div>
         <div class="other_dis fr">
         </div>
         </section>
         </div>
         </section>
        
         </section>
        
        </template>
        
        <script>
         import {
         addMyshopcart,
         } from 'src/service/getData'
        
         export default {
         name: 'one_business',
         props: {
         search_text:String,
         item:{}
         },
         data () {
         return {
         msg: '1'
        
         };
         },
         mounted () {
        
         },
         computed: {
         isLogin () {
         return this.$store.getters.getLogin;
         },
         ruleTitle() {
         let titleString = this.item.gname;
         if (!titleString) {
         return '';
         }
         if (this.search_text && this.search_text.length > 0) {
         // 匹配關(guān)鍵字正則
         let replaceReg = new RegExp(this.search_text, 'g');
         // 高亮替換v-html值
         let replaceString = '<span class="search-text">' + this.search_text + '</span>';
         // 開始替換
         titleString = titleString.replace(replaceReg, replaceString);
         }
         return titleString;
         }
         },
         methods: {
         async add_cart(id){
         if (!this.isLogin) {
         this.$router.replace('/login');
         } else {
         var userId = this.$store.getters.getuname;
         var result = await addMyshopcart(id, userId)
         console.log(result.resMsg)
        
         if (result.res === 1) {
         this.$router.replace('/ShopCart/' + userId);
         } else {
         alert(result.resMsg)
         }
         }
         }
         }
        
         };
        </script>
        
        <!-- Add "scoped" attribute to limit CSS to this component only -->
        <style lang="less">
         @baseBlue: #0096ff;
         @com_gray1: #666;
         @com_gray2: #999;
        .search-text{
         color: #52250a;
         background: #ffd930;
         font-size: .2rem;
         padding: .02rem;
         border-radius: 2px;
         vertical-align: top;
         margin-right: .04rem;
        }
        
        
         .com_gray1 {
         color: @com_gray1;
         }
        
         .com_gray2 {
         color: @com_gray2;
         }
        
         .com_blue {
         color: @baseBlue;
         }
        
         /* 單個(gè)商家 */
         .one_business {
         background: #fff;
        
         .business_img {
         width: 1.6rem;
         height: 1.6rem;
         padding: 0.4rem;
         float: left;
         img {
         width: 100%;
         height: 100%;
         }
         }
         .business_info {
         float: right;
         width: 7.4rem;
         height: 1.6rem;
         padding: 0.4rem .2rem .4rem 0;
         .business_name {
         font-size: .35rem;
         line-height: .45rem;
         vertical-align: top;
         h3 {
         width: 5rem;
         display: inline-block;
         /*span {*/
         /*color: #52250a;*/
         /*background: #ffd930;*/
         /*font-size: .2rem;*/
         /*padding: .02rem;*/
         /*border-radius: 2px;*/
         /*vertical-align: top;*/
         /*margin-right: .04rem;*/
         /*}*/
         }
         .bzp {
         width: .3rem;
         height: .3rem;
         font-size: .26rem;
         text-align: center;
         line-height: .3rem;
         display: inline-block;
         color: @com_gray2;
         border: 0.01rem solid #ddd;
         padding: 0.01rem;
         border-radius: 3px;
         i {
         font-style: normal;
         }
        
         }
         }
         .business_code, .business_other {
         font-size: .25rem;
         margin-top: .3rem;
         line-height: .25rem;
         }
        
         }
         .code_num {
         svg {
         width: .3rem;
         height: .3rem;
         fill: #ffaa0c;
         }
         }
         .zsd {
         font-size: .25rem;
         height: .35rem;
         line-height: .3rem;
         padding: 0 0.05rem;
         display: inline-block;
         color: @baseBlue;
         background: #fff;
         border: 0.01rem solid @baseBlue;
         box-sizing: border-box;
         border-radius: 3px;
         }
         .fnzs {
         font-size: .25rem;
         height: .35rem;
         padding: 0 0.05rem;
         line-height: .3rem;
         display: inline-block;
         background: @baseBlue;
         color: #fff;
         border: 0.01rem solid @baseBlue;
         box-sizing: border-box;
         border-radius: 3px;
         }
         }
        </style>

        聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        Vue實(shí)現(xiàn)搜索結(jié)果高亮顯示關(guān)鍵字

        本文實(shí)例為大家分享了Vue實(shí)現(xiàn)搜索結(jié)果高亮顯示關(guān)鍵字的具體代碼,供大家參考,具體內(nèi)容如下:1.需要解決的問題 父組件將搜索的字段傳到子組件 子組件接受數(shù)據(jù),正則匹配,并替換字段。2.具體代碼;父組件代碼;
        推薦度:
        標(biāo)簽: 搜索 VUE 關(guān)鍵詞
        • 熱門焦點(diǎn)

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 国产hs免费高清在线观看| 亚洲视频在线免费| A毛片毛片看免费| 午夜亚洲福利在线老司机| 亚洲精品无码你懂的| 国产在线国偷精品产拍免费| 亚洲日本国产精华液| 色猫咪免费人成网站在线观看 | 亚洲精品乱码久久久久久久久久久久| 亚洲综合无码一区二区痴汉| 成年女人18级毛片毛片免费观看| 亚洲人6666成人观看| av无码免费一区二区三区| 亚洲免费在线视频播放| 亚洲av无码国产精品色在线看不卡| 在线视频亚洲一区| 青青青国产色视频在线观看国产亚洲欧洲国产综合 | 亚洲国产精品激情在线观看| 99re这里有免费视频精品| 亚洲视频在线观看视频| 国内精自视频品线六区免费| 免费人成动漫在线播放r18| 国产偷窥女洗浴在线观看亚洲| 久久成人永久免费播放| 亚洲精品美女网站| 全亚洲最新黄色特级网站| 5g影院5g天天爽永久免费影院| 中文无码亚洲精品字幕| 国产亚洲精品无码成人| 全免费A级毛片免费看网站| 成年免费大片黄在线观看com| 亚洲日韩精品一区二区三区| 一级毛片成人免费看免费不卡| 色九月亚洲综合网| 亚洲av永久无码嘿嘿嘿| 免费在线观看视频a| 久久久久久久岛国免费播放| 色多多免费视频观看区一区| 亚洲AV永久精品爱情岛论坛| 国产香蕉免费精品视频| 日本一区二区免费看|