处理边界情况之X-template

点击打开视频讲解更加详细

另一个定义模板的方式是在一个元素中,并为其带上 text/x-template 的类型,然后通过一个 id 将模板引用过去。例如:

  

Hello hello hello

Vue.component('hello-world', {  template: '#hello-world-template'})

x-template 需要定义在 Vue 所属的 DOM 元素外。

这些可以用于模板特别大的 demo 或极小型的应用,但是其它情况下请避免使用,因为这会将模板和该组件的其它定义分离开。

完整案例:

                末晨曦吖    

Hello hello hello

Vue.component('hello-world', { template: '#hello-world-template' }) var app = new Vue({ el:'#app' }) body{ padding: 0; margin: 0; }

若对您有帮助,请点击跳转到B站一键三连哦!感谢支持!!!