父组件为子组件传值为undefined
来源:1-5 项目作业
TKXZ
2023-06-28 10:39:12
父组件:
<template>
<TopArea :title="新建收货地址" :topFunctionText="保存" />
</template>
<script>
import TopArea from './TopArea.vue'
export default {
name: 'CreateAddress',
components: { TopArea },
setup() {
},
}
</script>
<style lang="scss" scoped>
</style>子组件:
<template>
<div class="top">
<div class="iconfont backIcon" @click="handleBack"></div>
<div class="top__title">{{ title ? title : '管理收货地址' }}</div>
<div class="top__create" @click="() => {topFunction ? topFunction() : handleCreateAddress()}">
{{topFunctionText ? topFunctionText : '新建'}}
</div>
</div>
</template>
<script>
import { useRouter } from 'vue-router'
//跳转页面逻辑
const goPages = () => {
const router = useRouter();
const handleBack = () => {
router.back();
}
const handleCreateAddress = () => {
router.push({name: 'CreateAddress'});
}
return { handleBack, handleCreateAddress }
}
export default {
name: 'TopArea',
props: [ 'title', 'topFunction', 'topFunctionText' ],
setup(props) {
const { handleBack, handleCreateAddress } = goPages();
console.log(props)
return { handleBack, handleCreateAddress }
},
}
</script>
<style lang="scss" scoped>
@import '../../style/variables.scss';
.top {
display: flex;
line-height: .44rem;
background-color: $bg-color;
padding: 0 .18rem;
.backIcon {
font-size: .18rem;
color: #B6B6B6;
transform: rotate(180deg);
}
&__title {
flex: 1;
text-align: center;
font-size: .16rem;
color: $content-font-color;
}
&__create {
font-size: .14rem;
color: $content-font-color;
}
}
</style>子组件无法使用父组件传递的值
1回答
同学你好,建议如下:
父组件:

子组件:

结果如下:


祝学习愉快!
相似问题
回答 2