最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Vue component using computed property of the mixin - Stack Overflow

programmeradmin1浏览0评论

I have a simple ponent that uses mixin that's shared across multiple ponents with similar functionality.

When I run it I seem to be getting

Property or method "activeClass" is not defined on the instance but referenced during render.

Here's my mixin

<script>
    export default {
        data() {
            return {
                opened: false,
                identity: ''
            }
        },
        puted: {
            activeClass() {
                return {
                    active: this.opened
                };
            }
        },
        created() {
            window.EventHandler.listen(this.identity + '-toggled', opened => this.opened = opened);
        },
        methods: {
            toggle() {
                window.EventHandler.fire('toggle-' + this.identity);
            }
        }
    }
</script>

and my ponent

<template>
    <span class="pointer" :class="activeClass" @click="toggle"><i class="fas fa-search"></i></span>
</template>
<script>
    import Trigger from '../../mixins/Trigger';
    export default {
        data() {
            return {
                mixins: [Trigger],
                data() {
                    return {
                        identity: 'language'
                    }
                }
            }
        }
    }
</script>

For some reason I cannot seem to be able to access activeClass puted property from within the ponent. Any idea why is this happening?

I have a simple ponent that uses mixin that's shared across multiple ponents with similar functionality.

When I run it I seem to be getting

Property or method "activeClass" is not defined on the instance but referenced during render.

Here's my mixin

<script>
    export default {
        data() {
            return {
                opened: false,
                identity: ''
            }
        },
        puted: {
            activeClass() {
                return {
                    active: this.opened
                };
            }
        },
        created() {
            window.EventHandler.listen(this.identity + '-toggled', opened => this.opened = opened);
        },
        methods: {
            toggle() {
                window.EventHandler.fire('toggle-' + this.identity);
            }
        }
    }
</script>

and my ponent

<template>
    <span class="pointer" :class="activeClass" @click="toggle"><i class="fas fa-search"></i></span>
</template>
<script>
    import Trigger from '../../mixins/Trigger';
    export default {
        data() {
            return {
                mixins: [Trigger],
                data() {
                    return {
                        identity: 'language'
                    }
                }
            }
        }
    }
</script>

For some reason I cannot seem to be able to access activeClass puted property from within the ponent. Any idea why is this happening?

Share Improve this question asked Mar 17, 2018 at 13:10 Sebastian SulinskiSebastian Sulinski 6,0557 gold badges43 silver badges67 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

Try to move mixin to ponents main scope. Not in data function rerurn

发布评论

评论列表(0)

  1. 暂无评论