-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
Closed
Description
如题,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
Metadata
Metadata
Assignees
Labels
No labels