|
26 | 26 | <div class="note-item shadow rounded w-full " v-for="(item,index) in list" :key="item.noteId"> |
27 | 27 | <div class="max-note-height relative" :style="{ |
28 | 28 | '--note-max-height': item.openFlag?'auto':'240px', |
29 | | - paddingBottom:item.needOpenFlag?'20px':0 |
| 29 | + paddingBottom:noteHeightMap[item.noteId]>240?'20px':0 |
30 | 30 | }"> |
31 | | - <render :id="item.noteId" @onHtmlChanged="onHtmlChange(item,index)" :tags="item.tags" :content="item.content.markdown" style="display: block"/> |
32 | | - <div v-if="item.needOpenFlag" @click="item.openFlag = !item.openFlag" class="cursor-pointer text-white" style="position: absolute;background: rgb(139 139 139 / 66%);bottom:0;width:100%;text-align: center;height: 20px;line-height: 20px"> |
| 31 | + <render :id="item.noteId" @onHtmlChanged="onHtmlChange(item)" :tags="item.tags" :content="item.content.markdown" style="display: block"/> |
| 32 | + <div v-if="noteHeightMap[item.noteId]>240" @click="item.openFlag = !item.openFlag" class="cursor-pointer text-white" style="position: absolute;background: rgb(139 139 139 / 66%);bottom:0;width:100%;text-align: center;height: 20px;line-height: 20px"> |
33 | 33 | 展开 / 收起 |
34 | 34 | </div> |
35 | 35 | </div> |
@@ -124,7 +124,6 @@ function loadList(searchKey = '') { |
124 | 124 | item.content = JSON.parse(item.content) |
125 | 125 | item.tags = JSON.parse(item.tags || '[]') |
126 | 126 | item.openFlag = false |
127 | | - item.needOpenFlag = false |
128 | 127 | return item |
129 | 128 | }) |
130 | 129 | }) |
@@ -210,18 +209,15 @@ onMounted(()=>{ |
210 | 209 | }) |
211 | 210 |
|
212 | 211 |
|
213 | | -const onHtmlChange = (item, index)=>{ |
| 212 | +const onHtmlChange = (item)=>{ |
214 | 213 | const noteId = item.noteId |
215 | 214 | const h = document.getElementById(noteId).clientHeight |
216 | | - if (h > 240){ |
217 | | - item.needOpenFlag = true |
218 | | - list.value[index] = item |
219 | | - } |
| 215 | + noteHeightMap.value[noteId] = h |
| 216 | +} |
220 | 217 |
|
221 | | - item.height = h |
222 | 218 |
|
223 | | - console.log(item) |
224 | | -} |
| 219 | +const noteHeightMap = ref({}) |
| 220 | +
|
225 | 221 | </script> |
226 | 222 |
|
227 | 223 |
|
|
0 commit comments