Problem
In Vue 2, the root instance is treated more as a component than in Vue 1.
, Vue #app, #app vue. , , . Vue 2.
https://codepen.io/Fusty/pen/gqXavm?editors=1010
<style> Vue, . , - . , ( , Vue) vue , #app , DOM , , , ( <style> ).
@joestrouth1 # 6053 Vue-Land .
https://codepen.io/joestrouth1/pen/WPXrbg?editors=1011
. . , ,
"[Vue warn]: Error compiling template:
Templates should only be responsible for mapping the state to the UI. Avoid placing tags with side-effects in your templates, such as <style>, as they will not be parsed.
1 | <div>
2 | <style>
| ^^^^^^^
... etc ...
.
. , Vue 1. , , , 100% .
(, )
<style> DOM created Vue mounted . #app, , #app , Vue .
Vue <style> , Vue ( el: 'someSelector'), (, ) , Vue.
created: function() {
this.styleTagNodeList = document.querySelector(this.$options.el).querySelectorAll('style');
},
mounted: function() {
for(var i = 0; i < this.styleTagNodeList.length; ++i)
this.$el.appendChild(this.styleTagNodeList[i]);
}
: , , , , . .