Hi, everyone, I am testing following scenario: I have created one component which will be dynamically mounted to a dom with some id; when i click one element(which has a @click handler bound with it, i will initiate that component and mount it into dom. My question is: I have inspected in the devtool, that new inserted vue component can not be seen as a child of root vue instance. What is the problem? Is this the normal case or what i have done wrong with? Please see following code: http://jsbin.com/fikida/edit?html,js,console,output
Thanks~! here is the code:
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.16/vue.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<div id="root" >
<div @click="onclick">this is root</div>
</div>
<script type="x/templates" id="comp">
this is dynamically mounted component
</script>
<script>
new Vue({
el: "#root",
methods: {
onclick: function(e){
var subcomp = Vue.extend({
template: "#comp",
data: {
subcompdata: "sub component data"
}
});
new subcomp().$mount(e.target);
}
},
data: {
rootcompdata: "root vue data"
}
});
</script>
</body>
</html>