I am getting the following error in IE11 when using the template tag:
[Vue warn]: Unknown custom element: <template> - did you register the component correctly?
In FireFox, I do not have an issue when using the template tag for my templates. In IE11, the issue goes away if I replace the template tag with <script type="text/template">
.
<template>
is not natively supported in all browsers. Also please provide a repro of how you are using it. If you are using the <template>
as an inline template then you should not be compiling it.
I looked around for <template>
compatibility and it looks like IE11 does not recognize it (even though FireFox and Chrome support it in older versions).
Here's an example:
<user hello="Hello User"></user>
<template id="user-template">
<button @click="sayHello">Say Hello!</button>
</template>
<script type="text/javascript">
var componentUser = {
template: '#user-template',
props: ['hello'],
methods: {
sayHello: function() {
console.log( this.hello );
}
}
};
new Vue({
el: 'body',
components: {
'user': componentUser
}
});
</script>
Ok, so here's the things to note:
<body>
, or put your "templates" in <head>
instead.<script type="x/templates">
if you want cross-browser compatibility.I would add my two cents:
@englishextra Could you elaborate on this? Maybe with an example?
@jlmmns this will work fine with IE11
<style>
template {
display: none;
}
</style>
<script>
(function(){return (function templatePolyfill(){"use strict";if("content"in document.createElement("template")){return false;}var templates=document.getElementsByTagName("template");var plateLen=templates.length;for(var x=0;x<plateLen;++x){var template=templates[x];var content=template.childNodes;var fragment=document.createDocumentFragment();while(content[0]){fragment.appendChild(content[0]);}template.content=fragment;}}());}());
</script>
</head>
<body>
<template id="template_aside">
...
</template>
@englishextra Thank you!!!
Most helpful comment
Ok, so here's the things to note:
<body>
, or put your "templates" in<head>
instead.<script type="x/templates">
if you want cross-browser compatibility.