fix(deps): 修复自定义指令引起的热更新失效问题

ISSUES CLOSED: #45
This commit is contained in:
zclzone 2023-08-04 22:07:20 +08:00
parent 53830256f4
commit 65d4d3848d
5 changed files with 157 additions and 188 deletions

View File

@ -35,7 +35,6 @@
"@vueuse/core": "^10.2.1", "@vueuse/core": "^10.2.1",
"@wangeditor/editor": "^5.1.23", "@wangeditor/editor": "^5.1.23",
"@wangeditor/editor-for-vue": "^5.1.12", "@wangeditor/editor-for-vue": "^5.1.12",
"@zclzone/utils": "^0.0.13",
"axios": "^1.4.0", "axios": "^1.4.0",
"dayjs": "^1.11.9", "dayjs": "^1.11.9",
"lodash-es": "^4.17.21", "lodash-es": "^4.17.21",

315
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -11,7 +11,6 @@
<div <div
ref="content" ref="content"
v-resize="refreshIsOverflow"
class="content" class="content"
:class="{ overflow: isOverflow && showArrow }" :class="{ overflow: isOverflow && showArrow }"
:style="{ :style="{
@ -24,8 +23,7 @@
</template> </template>
<script setup> <script setup>
import { debounce } from '@/utils' import { debounce, useResize } from '@/utils'
import { useResize } from '@zclzone/utils'
defineProps({ defineProps({
showArrow: { showArrow: {
@ -78,14 +76,17 @@ const resetTranslateX = debounce(function (wrapperWidth, contentWidth) {
} }
}, 200) }, 200)
const observer = ref(null) const observers = ref([])
onMounted(() => { onMounted(() => {
refreshIsOverflow() refreshIsOverflow()
observer.value = useResize(document.body, refreshIsOverflow) observers.value.push(useResize(document.body, refreshIsOverflow))
observers.value.push(useResize(content.value, refreshIsOverflow))
}) })
onBeforeUnmount(() => { onBeforeUnmount(() => {
observer.value?.disconnect() observers.value.forEach((item) => {
item?.disconnect()
})
}) })
function handleScroll(x, width) { function handleScroll(x, width) {

View File

@ -8,7 +8,6 @@ import { createApp } from 'vue'
import { setupRouter } from '@/router' import { setupRouter } from '@/router'
import { setupStore } from '@/store' import { setupStore } from '@/store'
import App from './App.vue' import App from './App.vue'
import { useResize } from '@zclzone/utils'
import { setupNaiveDiscreteApi } from './utils' import { setupNaiveDiscreteApi } from './utils'
async function setupApp() { async function setupApp() {
@ -19,7 +18,6 @@ async function setupApp() {
await setupRouter(app) await setupRouter(app)
app.use(useResize)
app.mount('#app') app.mount('#app')
} }

View File

@ -74,3 +74,17 @@ export function debounce(method, wait, immediate) {
} }
} }
} }
/**
*
* @param {HTMLElement} el
* @param {Function} cb
* @return {ResizeObserver}
*/
export function useResize(el, cb) {
const observer = new ResizeObserver((entries) => {
cb(entries[0].contentRect)
})
observer.observe(el)
return observer
}