在使用 vue-cli 构建项目时(使用的模版是webpack)
初始化的 main.js 中是这样的。
/* eslint-disable no-new */
new Vue({
el: '#app',
router,
template: '<App/>',
components: { App }
});
然后将挂载点改为: el: 'body' ,然后浏览器就会报这个警告:
[Vue warn]: Do not mount Vue to <html> or <body> - mount to normal elements instead.
原因:
本文探讨了使用Vue.js时选择合适挂载点的重要性,并详细解释了为何不应将Vue实例挂载到<html>或<body>元素上。通过实际案例展示了不当挂载点可能导致的问题。
1947

被折叠的 条评论
为什么被折叠?



