-
-
Notifications
You must be signed in to change notification settings - Fork 7
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
希望增加一个配置不需要在每个页面都定义uniLayout的ref #41
Labels
enhancement
New feature or request
Comments
可以结合例子说明一下?没能理解其中的关联? |
<script setup>
const toastRef = ref()
defineExpose({
toastRef
})
</script>
<template>
<view class="page-app">
<toast ref="toastRef" />
</view>
</template>
/**
* @description 显示消息提示框
* @param {string} title 提示的内容,长度与 icon 取值有关。
* @param {number} duration 提示的延迟时间,单位毫秒,默认:2000
*/
export function toast(title: string, type?: 'none' | 'success' | 'loading' | 'error' | 'fail' | 'exception' | 'warning' | undefined, duration = 1000, complete?: AnyFn) {
try {
let hasIcon = true
if (type === undefined || type === 'none')
hasIcon = false
const pages = pagesInstance()
if (pages.length > 0) {
pages[pages.length - 1].$vm.$refs.uniLayout.toastRef.show({
type,
icon: hasIcon,
message: title,
duration,
complete,
})
}
}
catch (err) {
if (type === 'warning')
type = 'none'
uni.showToast({
title: String(title),
icon: type || 'none',
duration,
})
}
} 通过refs调取每个页面上的toast组件,我就要在每个页面上写 const uniLayout = ref() ,不然获取不到 uniLayout |
@ModyQyW 大哥,看看这个issue |
在一个页面内 咱能否放一个option: |
由于团队各成员时间问题,欢迎各位朋友提交该与功能相关的PR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
对问题的清晰和简明的描述
我在layouts写了公共组件并且defineExpose 抛出。我要通过PageInstance获取每个页面的方法
推荐的解决方案
在配置中增加是否自动加入ref,而不是需要每个页面添加const uniLayout = ref()
替代方案
No response
额外上下文
No response
检查
The text was updated successfully, but these errors were encountered: