🐛(component): [修复] page 组件 外部更改v-model视图不刷新问题

This commit is contained in:
0o张不歪o0 2022-07-13 09:27:59 +08:00
parent 65f0e1b82e
commit ce2ccd8a75
3 changed files with 31 additions and 48 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@layui/layui-vue", "name": "@layui/layui-vue",
"version": "1.2.9", "version": "1.3.0-alpha.1",
"author": "就眠儀式", "author": "就眠儀式",
"license": "MIT", "license": "MIT",
"description": "a component library for Vue 3 base on layui-vue", "description": "a component library for Vue 3 base on layui-vue",

View File

@ -77,7 +77,7 @@ const totalPage = computed(() => {
const currentPage: Ref<number> = ref(props.modelValue); const currentPage: Ref<number> = ref(props.modelValue);
const currentPageShow: Ref<number> = ref(currentPage.value); const currentPageShow: Ref<number> = ref(currentPage.value);
const emit = defineEmits(["jump", "limit"]); const emit = defineEmits(["jump", "limit", 'update:modelValue']);
const prev = function () { const prev = function () {
if (currentPage.value === 1) { if (currentPage.value === 1) {
@ -106,56 +106,47 @@ watch(inlimit, function () {
}); });
watch(currentPage, function () { watch(currentPage, function () {
if (currentPage.value > totalPage.value[totalPage.value.length - 1]) {
currentPage.value = totalPage.value[totalPage.value.length - 1];
}
if (currentPage.value < totalPage.value[0]) {
currentPage.value = totalPage.value[0];
}
currentPageShow.value = currentPage.value; currentPageShow.value = currentPage.value;
emit("jump", { current: currentPage.value }); emit("jump", { current: currentPage.value });
emit('update:modelValue', currentPage.value)
}); });
watch(() => props.modelValue, function () {
currentPage.value = props.modelValue
currentPageShow.value = currentPage.value
})
</script> </script>
<template> <template>
<div class="layui-laypage layui-laypage-default"> <div class="layui-laypage layui-laypage-default">
<span v-if="showCount" class="layui-laypage-count" <span v-if="showCount" class="layui-laypage-count"> {{ total }} {{ maxPage }} </span>
> {{ total }} {{ maxPage }} </span <a href="javascript:;" class="layui-laypage-prev" :class="[
>
<a
href="javascript:;"
class="layui-laypage-prev"
:class="[
currentPage === 1 ? 'layui-disabled' : '', currentPage === 1 ? 'layui-disabled' : '',
theme && currentPage !== 1 ? 'layui-laypage-a-' + theme : '', theme && currentPage !== 1 ? 'layui-laypage-a-' + theme : '',
]" ]" @click="prev()">
@click="prev()"
>
<slot v-if="slots.prev" name="prev"></slot> <slot v-if="slots.prev" name="prev"></slot>
<template v-else>{{ t("page.prev") }}</template> <template v-else>{{ t("page.prev") }}</template>
</a> </a>
<template v-if="showPage"> <template v-if="showPage">
<template v-for="index of totalPage" :key="index"> <template v-for="index of totalPage" :key="index">
<span v-if="index === currentPage" class="layui-laypage-curr"> <span v-if="index === currentPage" class="layui-laypage-curr">
<em <em class="layui-laypage-em" :class="[theme ? 'layui-bg-' + theme : '']"></em>
class="layui-laypage-em"
:class="[theme ? 'layui-bg-' + theme : '']"
></em>
<em>{{ index }}</em> <em>{{ index }}</em>
</span> </span>
<a <a v-else href="javascript:;" @click="jump(index)" :class="[theme ? 'layui-laypage-a-' + theme : '']">{{ index
v-else }}</a>
href="javascript:;"
@click="jump(index)"
:class="[theme ? 'layui-laypage-a-' + theme : '']"
>{{ index }}</a
>
</template> </template>
</template> </template>
<a <a href="javascript:;" class="layui-laypage-next" :class="[
href="javascript:;"
class="layui-laypage-next"
:class="[
currentPage === maxPage ? 'layui-disabled' : '', currentPage === maxPage ? 'layui-disabled' : '',
theme && currentPage !== maxPage ? 'layui-laypage-a-' + theme : '', theme && currentPage !== maxPage ? 'layui-laypage-a-' + theme : '',
]" ]" @click="next()">
@click="next()"
>
<slot v-if="slots.next" name="next"></slot> <slot v-if="slots.next" name="next"></slot>
<template v-else>{{ t("page.next") }}</template> <template v-else>{{ t("page.next") }}</template>
</a> </a>
@ -171,18 +162,9 @@ watch(currentPage, function () {
</a> </a>
<span v-if="props.showSkip" class="layui-laypage-skip"> <span v-if="props.showSkip" class="layui-laypage-skip">
到第 到第
<input <input v-model="currentPageShow" @keypress.enter="jumpPage()" type="number"
v-model="currentPageShow" class="layui-input layui-input-number" />
@keypress.enter="jumpPage()" <button type="button" class="layui-laypage-btn" @click="jumpPage()" :disabled="currentPageShow > maxPage">
type="number"
class="layui-input layui-input-number"
/>
<button
type="button"
class="layui-laypage-btn"
@click="jumpPage()"
:disabled="currentPageShow > maxPage"
>
确定 确定
</button> </button>
</span> </span>

View File

@ -17,6 +17,7 @@
<h3>1.3.0 <span class="layui-badge-rim">2022-07-12</span></h3> <h3>1.3.0 <span class="layui-badge-rim">2022-07-12</span></h3>
<ul> <ul>
<li><span style="color:#FF5722">[破坏性更新]</span> 统一checkbox与radio属性语义 两个组件受到影响 label代表显示值value代表绑定值。 by @SmallWai</li> <li><span style="color:#FF5722">[破坏性更新]</span> 统一checkbox与radio属性语义 两个组件受到影响 label代表显示值value代表绑定值。 by @SmallWai</li>
<li>[修复] page 组件 外部更改v-model视图不刷新问题。 by @SmallWai</li>
</ul> </ul>
</li> </li>
</ul> </ul>