-
-
Notifications
You must be signed in to change notification settings - Fork 17.5k
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
[feature request] can we consider extracting props for export #3107
Comments
Translation of this issue: Existing ComponentYes Component Namebutton DescriptionSome business scenarios require secondary encapsulation of components. For example, I want to encapsulate a plus button. This component inherits all the attributes of El button and then extends some attributes. I want to inherit all the props of El button. At present, because the props of El button are written in the component and are not exposed to the outside world, it cannot be referenced, Although it can also be implemented with v-bind = $attrs at present, this experience is not very good. Ts and IDE cannot infer relevant attributes. If props files can be exposed to the outside world, relevant attributes can be easily deduced by TS inheritance |
+1. |
@zouyaoji @pangao66
<script lang="ts" setup>
import CustomButton from './CustomButton.vue'
</script>
<template>
<custom-button text-color="red" size="large">Hello world</custom-button>
</template>
<script lang="ts" setup>
import { buttonProps } from 'element-plus'
const props = defineProps({
...buttonProps,
textColor: String,
})
</script>
<template>
<el-button v-bind="props" :style="{ color: props.textColor }">
<slot></slot>
</el-button>
</template> |
收到,非常感谢
…------------------ 原始邮件 ------------------
发件人: "element-plus/element-plus" ***@***.***>;
发送时间: 2022年1月13日(星期四) 晚上11:09
***@***.***>;
***@***.******@***.***>;
主题: Re: [element-plus/element-plus] [feature request] can we consider extracting props for export (#3107)
@zouyaoji @pangao66
Please consider the code below.
App.vue
<script lang="ts" setup> import CustomButton from './CustomButton.vue' </script> <template> <custom-button text-color="red" size="large">Hello world</custom-button> </template>
CustomButton.vue
<script lang="ts" setup> import { buttonProps } from 'element-plus' const props = defineProps({ ...buttonProps, textColor: String, }) </script> <template> <el-button v-bind="props" :style="{ color: props.textColor }"> <slot></slot> </el-button> </template>
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
This is a solution, but it doesn't seem very friendly either。 For projects based on element-plus secondary development, many custom components will be added. According to this statement: Is it possible that only Element Plus maintains the type definition of each component separately to better solve this problem. |
...没看懂你这个 issue。 |
@zouyaoji |
@sxzz 希望能很方便的这样定义一个变量 而且让我特别困惑的是,这个ButtonProp类型鼠标滑上去,看起来很多都是有"?"的可选属性啊, 如果没写,怎么还会提示缺了。。。 |
嗯 我刚试了一下 String 类型确实是这样,去掉default就是可选的了。 但是 Boolean 类型好像不行,这咋搞 - - |
@zouyaoji 这个可能得自己用 TS 实现了。。 |
@sxzz 所以我好希望vue官方给解决这个问题,有类似的需求就不用再专门维护TS类型声明了。 尤大回复这个是说没必要这么搞吗? |
@zouyaoji 你那个issue的图片不是动图,有歧义。 |
嗯 我明白了 感谢你的答疑解惑。 我准备把这边的讨论附过去,希望能表达清楚我的真实需求。 |
Existing Component
Yes
Component Name
button
Description
有些业务场景 需要对组件进行二次封装, 比如 我想封装一个plus-button 这个组件继承el-button所有的属性, 然后自己又扩展一些属性, 我想给它继承el-button的所有的props 目前由于el-button的props是写在组件里面的没有对外暴露, 无法引用, 虽然目前也能用 v-bind=$attrs实现, 但是这个体验不太好, ts和ide无法推断相关属性 如果props文件能够对外暴露 则可以利用ts 继承 很容易推导出相关属性
The text was updated successfully, but these errors were encountered: