今天学习完了搭建脚手架2,对runtime-only和runtime-compiler的理解不是很熟练,本不想写这篇博客的,但觉得会有帮助,所以最后有了这篇博客。
左侧图片是使用runtime-compiler,右侧图片是使用runtime-only,这两者的区别在于能否解析template模板,前者能够解析,而后者不能解析。
runtime-compiler在遇到.vue文件时,就是当作vue使用,所以能够解析template。但是runtime-only在遇到.vue文件时,解析为.js文件,其中的tempalte会转化为render函数。具体步骤如下所示:
runtime-compiler工作过程是template->ast->render函数->vDOM->DOM->UI
runtime-only工作的过程是 render函数->vDOM->UI
在vscode加载项目时,推荐的是runtime-compiler,但是runtime-only的优点很多,比如更轻、编译速度更快,中间减少了不少步骤
在runtime-only中,template之所以能够转化为render函数,是因为我们在安装vue时,安装了vue-template-compiler
**"vue-template-compiler": "^2.5.2",**