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

类型应该是MaybeRef #5093

Closed
palmerye opened this issue Jul 24, 2023 · 5 comments
Closed

类型应该是MaybeRef #5093

palmerye opened this issue Jul 24, 2023 · 5 comments
Labels
untriaged need to sort

Comments

@palmerye
Copy link

TuSimple/naive-ui version (版本)

2.34.4

Vue version (Vue 版本)

3.3.4

Browser and its version (浏览器及其版本)

Chrome 114.0.5735.198

System and its version (系统及其版本)

macOS 13.2.1

Node version (Node 版本)

Reappearance link (重现链接)

https://www.naiveui.com/zh-CN/os-theme/components/dialog#useDialog-API

Reappearance steps (重现步骤)

import { defineComponent, ref } from 'vue'
import { useMessage, useDialog } from 'husky-ui'

export default defineComponent({
  setup() {
    const message = useMessage()
    const dialog = useDialog()
    const loadingLoac = ref(true)
    return {
      loadingLoac,
      handleCreate() {
        dialog.create({
          title: '确定删除xxx吗?(把title故意写得很长为了看看两行的效果)',
          content: '这是一串小内容。。。',
          positiveText: '确定',
          negativeText: '关闭',
          loading: loadingLoac,
          onPositiveClick: () => {
            message.success('确定')
          },
          onNegativeClick: () => {
            message.error('不确定')
            loadingLoac.value = !loadingLoac.value
            return false
          }
        })
      },
    }
  }
})

Expected results (期望的结果)

loading 类型提示正确

Actual results (实际的结果)

不能将类型“Ref”分配给类型“boolean | undefined”。ts(2322)
image

Remarks (补充说明)

@github-actions github-actions bot added the untriaged need to sort label Jul 24, 2023
@palmerye
Copy link
Author

image

@jizai1125
Copy link
Contributor

传给 loading 属性不能是 ref

@palmerye
Copy link
Author

传给 loading 属性不能是 ref

那样就无法响应式了。

场景:dialog 弹出时loading为true,button呈现loading;此时调用异步逻辑,有回调后要使loading关闭。用ref是能实现场景的需求,但ts报type类型错误。

@jizai1125
Copy link
Contributor

传给 loading 属性不能是 ref

那样就无法响应式了。

场景:dialog 弹出时loading为true,button呈现loading;此时调用异步逻辑,有回调后要使loading关闭。用ref是能实现场景的需求,但ts报type类型错误。

create 方法会返回一个 reactive 包裹的 options,你可以直接改,例如:

const dialog = useDialog()
const d = dialog.create({})
d.loading = true

@jahnli
Copy link
Collaborator

jahnli commented Mar 12, 2024

This issue does not have any recent activity. If you are still experiencing similar problems, open a new error, including a minimal copy of the problem

@jahnli jahnli closed this as completed Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
untriaged need to sort
Projects
None yet
Development

No branches or pull requests

3 participants