慕虎7371278
2021-05-14 18:16:37
我是vue的新手,并且創(chuàng)建了一個(gè)可搜索的數(shù)據(jù)庫表?,F(xiàn)在,當(dāng)我執(zhí)行搜索時(shí),我想知道輸入搜索詞時(shí)獲得的點(diǎn)擊數(shù)。我發(fā)現(xiàn)行數(shù)/匹配數(shù)應(yīng)該存儲(chǔ)在totalRows中,但是當(dāng)我打印時(shí),我得到的只是1。它似乎不存儲(chǔ)匹配數(shù)。在網(wǎng)上我可以找到多個(gè)解決方案,但是只有在您安裝了某些依賴項(xiàng)時(shí)才能找到。我想避免他們。還有其他選擇來獲得點(diǎn)擊數(shù)嗎?謝謝。 <template><!-- Header --><div class="card pl-3"> <div class="card-body pb-1"> <h3 class="card-title">Create </h3> <div class="card-body"> <b-container fluid> <!-- User Interface controls --> <b-row> <b-col md="5" class="my-1"> <b-form-group label-cols-sm="3" label="Filter" class="mb-1"> <b-input-group> <b-form-input v-model="itemSearch" placeholder="Search ..."></b-form-input> <b-input-group-append> <b-button :disabled="!itemSearch" @click="itemSearch = ''">Clear</b-button> </b-input-group-append> </b-input-group> </b-form-group> </b-col>目前,我剛得到404。我所有值的總數(shù)。輸入搜索字詞時(shí)它不會(huì)改變。
2 回答

慕無忌1623718
TA貢獻(xiàn)1744條經(jīng)驗(yàn) 獲得超4個(gè)贊
無需computed
用于hits
。只顯示totalRows
,因?yàn)檫@實(shí)際上是搜索結(jié)果的數(shù)量。
也不要使用v-once
,因?yàn)槟噲D多次渲染DOM的這一部分。
刪除v-once
并顯示totalRows
:
<span>Total number of hits: {{ totalRows }}</span>
順便說一句,該計(jì)算的屬性hits
將不會(huì)顯示與搜索匹配的行數(shù)。因?yàn)樗举|(zhì)上是回歸的this.items.length
;但items
不會(huì)被修改,因此它將始終是相同的值。

犯罪嫌疑人X
TA貢獻(xiàn)2080條經(jīng)驗(yàn) 獲得超4個(gè)贊
我是vue的新手,所以我不確定。但是我認(rèn)為v-once指令阻止Vue重新呈現(xiàn)您的標(biāo)簽。因此,當(dāng)您的匹配在中更新時(shí)<span v-once>Total number of hits: {{ hits}}</span>
,Vue不會(huì)重新呈現(xiàn)您的標(biāo)簽。嘗試也刪除v-once指令,它應(yīng)該起作用,...我認(rèn)為;)
添加回答
舉報(bào)
0/150
提交
取消