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

activate钩子在mixin的时候不会正确执行 #2305

Closed
graysheeep opened this issue Feb 5, 2016 · 0 comments
Closed

activate钩子在mixin的时候不会正确执行 #2305

graysheeep opened this issue Feb 5, 2016 · 0 comments

Comments

@graysheeep
Copy link

如题,mixin里写了activate钩子,组件里也写了一个,按照文档mixin里的钩子会先于组件执行,事实上组件里的activate会先执行并且mixin里的钩子不会再次执行。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <button @click="toggleComp">I am a button</button>
    <component :is="currentView"></component>
</body>
<script src="vue.js"></script>
<script>
    var mixin = {
        activate: function(done) {
            console.log('hook activate');
            done();
        }
    };

    var vue = new Vue({
        el:'body',
        data:{
            currentView:'comp1'
        },
        components:{
            comp1:{
                mixins:[mixin],
                template:'<h1>I am comp1</h1>',
                activate: function(done) {
                    console.log('comp1 activate');
                    done();
                }
            },
            comp2:{
                mixins:[mixin],
                template:'<h1>I am comp2</h1>',
                activate: function(done) {
                    console.log('comp2 activate');
                    done();
                }
            }
        },
        methods:{
            toggleComp:function() {
                this.currentView = this.currentView === 'comp1' ? 'comp2':'comp1'
            }
        }
    })
</script>
</html>

![vue-issue](https://cloud.githubusercontent.com/assets/4529986/12847277/1d9b2cc4-cc4d-11e5-9e1d-0d6c6b36dcb9.png

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant