1.components 定义count数值,str字符串,unpdateCount函数
<script setup>
defineExpose({
count,
str:"咸虾米",
updateCount
})
</script>
2.pages
<template>
<view class="layout">
<demo-child ref="child"></demo-child>
<view>----</view>
<button @click="update">点击修改子值</button>
</view>
</template>
<script setup>
import {
onMounted,
ref
} from "vue";
const child = ref(null);
const update = function() {
child.value.updateCount()
console.log(child.value.str);
}
onMounted(() => {
console.log(child.value);
})
</script>
<style lang="scss" scoped>
</style>