Vue.component('visit-root',{
template:`
<div>
<div>{
{this.$root.foo}}</div>
<div>{
{this.$root.two =12}}</div>
</div>
`
})
new Vue({
el:"#demo",
data:{
foo:1,
two:12
},
computed:{
bar:function(){
console.log("bar")
}
},
methods:{
baz:function(){
console.log("baz")
}
}
})
参考:https://www.cnblogs.com/gongshunfeng91/p/11301497.html