使用Vue 2.0,您无法将根实例安装到body或html元素.您将获得[Vue警告]:不要将Vue挂载到< html>或者< body> – 改为安装到普通元素.错误信息.
The provided element merely serves as a mounting point. Unlike in Vue 1.x, the mounted element will be replaced with Vue-generated DOM in all cases. It is therefore not recommended to mount the root instance to or
.解决方法是在组件mount()事件上手动移动元素.
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
Test 2-way binding
示例工作流程
new Vue({
el: '#app',
data: {
msg: 'message'
},
components: {
'navbar': {
template: `{{ msg }}`,
props: ['msg'],
mounted() {
document.body.insertBefore(this.$el, document.body.firstChild)
}
}
}
})