Tencent / wepy

小程序组件化开发框架
https://wepyjs.gitee.io/wepy-docs/
Other
22.48k stars 3.06k forks source link

子页面继承父页面无法正常显示component #1641

Closed e8wow closed 5 years ago

e8wow commented 5 years ago

Description

[问题描述:站在其它人的角度尽可能清晰地、简洁地把问题描述清楚]

[Description of the issue]

希望通过mixin或es6的继承去继承一个基类页面,实现全局组件,子页面components属性已经继承或混合到但却无法正常显示组件

Environment

Reproduce

[如何重现问题]

[How to reproduce the issue]

在BasePage页面中引入继承了wepy.component的组件,并填写了对应的components属性或使用mixin混合components属性

Observed Results

[实际表现]

[Observed Results]

子Page无法正常显示组件

Expected Results

[期望表现]

[Expected Results]

子组件继承父组件的组件,并正常展示

Relevant Code / Logs

<!-- BasePage -->
<script>
    import wepy from 'wepy';

    import Copyright from './Copyright'
    import PrimaryButton from './PrimaryButton'

    export default class BasePage extends wepy.page {
        components = {
            copyright: Copyright,
            'primary-button': PrimaryButton
        }
    }
</script>

<!-- 子页面 -->
<script>
 import BasePage from '../../../components/common/BasePage'

    export default class QRCodeLogin extends BasePage {
        constructor() {
            super()
        }
    }
</script>

或使用混合

// Base-mixin
import wepy from 'wepy';

import Copyright from '../components/common/Copyright.wpy'
import PrimaryButton from '../components/common/PrimaryButton.wpy'

export default class BaseBaseMixin extends wepy.mixin {
    components = {
        copyright: Copyright,
        'primary-button': PrimaryButton
    }
}

// 子页面
import BasePage from '../../../components/common/BasePage'

export default class QRCodeLogin extends BasePage {
    constructor() {
        super()
    }
    mixins = [BaseMixin]
}

子页面console.log打印实例后发现components属性已经继承过来了,但还是无法正常显示组件,在DOM中PrimaryButton组件就为

<primary-button></primary-button>
solgh commented 5 years ago

遇到同样的问题

zhuqling commented 5 years ago

Page继承只能继承js内容,这个有说明 Mixins混合不能继承components,这个是bug

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. 因为这个 Issue 最近没有任何有效回复,所以被自动标记为了stale。 如果在未来7天依旧没有任何激活操作,那么该 Issue 将会被自动关闭。 感谢您的提问。