父页面调用子组件代码失败,为什么?
问题描述:当state.showDialog = true时,页面上没有预期的子组件弹窗
<show-model :v-model="state.showDialog" @confirm="getLoanTime" />
子组件代码:
<template>
<view class="content">
<uni-popup ref="popup" v-model="state.show" mode="center" :animation="false" @close="cancel">
<uni-datetime-picker v-model="state.timeValue" type="datetime" />
<div>
<button @click="cancel">
取消
</button>
<button @click="confirm">
确定
</button>
</div>
</uni-popup>
</view>
</template>
<script lang="ts">
export default {
name: "ShowModel"
};
</script>
<script setup lang="ts">
import { reactive, watch } from 'vue';
const props = defineProps({
modelValue: {
type: Boolean,
default: false,
}
});
const state = reactive({
timeValue: '',
show: props.modelValue
});
watch(() => props.modelValue, (newVal) => {
state.show = newVal;
});
const cancel = () => {
state.show = false;
emit('update:modelValue', false);
};
const confirm = () => {
state.show = false;
emit('confirm', state.timeValue);
// 通知父组件关闭弹窗
emit('update:modelValue', false);
};
const emit = defineEmits(['update:modelValue', 'confirm']);
</script>
<style lang="scss">
.content{
z-index: 9999;
}
</style>