我是 Vue.js 的新手,我使用 AngularJS 一段时间了,在 Angular 中我们用来加载模板,例如,
template: '/sometemplate.html',
controller: 'someCtrl'
我们如何在 Vue 中做这样的事情,而不是像这样在 JavaScript 中保留大型 HTML 模板,
new Vue({
el: '#replace',
template: '<p>replaced</p>'
})
这对于小模板来说没问题,但是对于大模板来说这实用吗?
有没有办法像 Vue 一样加载外部模板 HTML 或在脚本标签内使用 HTML 模板?
<script type="x-template" id="template">HTML template goes here</html>
您可以通过引用脚本标签模板来使用它id
.
{
template: '#some-id'
}
Though, I highly recommend using vueify https://github.com/vuejs/vueify (if you use browserify) or vue-loader https://github.com/vuejs/vue-loader (if you use webpack) so you can have your components stored in nice little .vue
files like this.
另外,Vue 的作者写了一篇关于外部模板 url 主题的好文章:
https://vuejs.org/2015/10/28/why-no-template-url/ https://vuejs.org/2015/10/28/why-no-template-url/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)