Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用 props 来获取页面参数,路由没有参数,使用默认值无效 #5227

Open
sunpm opened this issue Nov 19, 2024 · 1 comment

Comments

@sunpm
Copy link

sunpm commented Nov 19, 2024

复现代码:https://github.com/sunpm/unisave/blob/uniapp-issue-props/src/pages/index/index.vue

image
image

<script setup lang="ts">
interface Props {
  name?: string
}

const props = withDefaults(defineProps<Props>(), {
  name: 'sunpm',
})

console.log('打印 name 参数', props.name) // 路由没有参数,打印则是 undefined
</script>

<template>
  <view flex="~ col items-center justify-center" p-50px>
    <h2>
      路由 props name:{{ name }}
    </h2>
  </view>
</template>

pages/hi.vue 还有 js 版本。
template 可以正确显示默认值,在 setup 获取不到

@sunpm
Copy link
Author

sunpm commented Dec 14, 2024

@Otto-J 辛宝麻烦看看

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant