uniapp 父类控件调子类组件的方法

2024-09-10  本文已影响0人  可乐小子

import { computed, ref, reactive, toRefs, onMounted } from 'vue'
const updateIsReadAll = ref(null)

const isReadAll = ref(false)

<view class="btn-read-all" @tap="readAll()">全部已读</view>

ref 绑定关联
<MessageList ref="updateIsReadAll" :isReadAll="isReadAll" />

2.const readAll = () => {

    uni.showModal({
        title: '提示',
        content: '是否设置当前标题项为全部已读?',
        success: (res) => {
            if (res.confirm) {
                console.log('用户点击确定按钮');
                isReadAll.value = true
                updateIsReadAll.value.updateIsReadAll()
            } else if (res.cancel) {
                console.log('用户点击取消');
                isReadAll.value = false
            }
        }
    });
}

3.子组件:
const props = defineProps({
isReadAll: {
// 搜索匹配关键词,用来处理高亮展示
type: Boolean,
default: false,
},
})

4.const updateIsReadAll = () => {

    let currentIndex = currentTab.value;
    let info = tabs.value[currentTab.value]
    console.log('info ===', info);
     
        //调取刷新全部已读的数据接口
        readAllApiInfo()
     
}

defineExpose({
updateIsReadAll
})

上一篇 下一篇

猜你喜欢

热点阅读