Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

为什么 Vue 使用 template:'<app/>' 可以将 components 中的 app 插入至页面

在默认的示例项目中,我看到了它设置

template:'<app/>,
components:{
    App
}

就可以实现html 页面中不需要设置<app></app> 就可以加载 App
请问这是什么原理?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

说来话长,不如你去看一下我为 vuejs.org 贡献的 pull request:

https://github.com/vuejs/vuej...

该 pr 主要分为三部分——
关于 el 的:
If neither render function nor template option is present, the in-DOM HTML of the mounting DOM element will be extracted as the template. In this case, Runtime + Compiler build of Vue should be used.
关于 template 的:
If render function is present in the Vue option, the template will be ignored.
关于 render 的:
The render function has priority over the render function compiled from template option or in-DOM HTML template of the mounting element which is specified by the el option.

官网中文版也有翻译。

之所以添加该部分内容,是因为 https://segmentfault.com/q/10... 这个问题


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...