1***@qq.com
1***@qq.com
  • 发布:2022-11-08 13:46
  • 更新:2022-11-08 15:40
  • 阅读:905

uniapp vue3.2+ts 语法中 怎么使用uni-popup 的ref? 能接收父组件传递的值,但是怎么让他和组件里的ref绑定呢?

分类:uni-app

//父组件
<template>
<view class="box">
aaa
</view>
<button @click="aaa">打开</button>
<popups :isShows="ishow"></popups>
</template>

<script setup lang="ts">
// import handleFun from "@/util/common/handleCallFun.js"
import { ref } from 'vue'
import popups from "@/components/abc.vue"
const ishow = ref(false)
const aaa = () => {
ishow.value = true
// console.log(ishow.value)

}
</script>
<style lang="scss" scoped>

</style>

//子组件
<template>
{{ isShows }}
<view class="pupup-login-box">
<uni-popup ref="isShows" type="bottom">底部弹出 Popup</uni-popup>
</view>
</template>

<script lang="ts" setup>
import { ref, watch } from 'vue'

interface Props {
isShows: Boolean
}
// const isShow: any = ref(false)

const { isShows } = defineProps<Props>()
console.log('aaaa',isShows)
// isShow.value = isShows
watch(
() => isShows,
(newVal, oldVal) => {
console.log("newVal==>", newVal);
console.log("oldVal==>", oldVal);

    // if (isShow.value) {  
    //     isShow.value.open();  
    //     console.log(isShow.value)  
    // }  
},  
{  
    immediate: true,  
    deep: true,  
}  

);

// const emits = defineEmits(["getUserInfoData"])

// const handleLogin = async () => {
// emits("getUserInfoData"); //让父组件获取个人信息
// }
</script>

<style lang="scss" scoped>

</style>

2022-11-08 13:46 负责人:无 分享
已邀请:
瀚海浪亭

瀚海浪亭 - 百度一下,我告诉你。

<template>  
    <subComponent ref="subComponentRef"></subComponent>  
</template>  

<script setup>  
    import { ref } from 'vue'  

    const subComponentRef = ref(null)  

    function onClick() {  
        subComponentRef.value.show = true  
    }  

    onLoad(() => {  
        setTimeout(() => {  
            onClick()  
        })  
    })  
</script>

该问题目前已经被锁定, 无法添加新回复