I am trying to use Vue.js without needing a build step. But Vue doesn't have a style property.
So I had an idea to create a custom "style" property on my Vue component instance and then inject the content of this property in the DOM when the component is created or mounted.
The only problem is I can't understand how to do it. (I looked at the plugins docs). I would need to create some sort of a plugin that would first check if a "style" property exists and then take it and insert it in the DOM. Also I don't want to use the Vue.component() function because I want to import and export using ES6. Here is how the result would look like:
// MyComponent.js
export default {
template: `<div>My component</div>`,
style: `
.hello {
background: #ccc;
}
`,
}
// App.js
import MyComponent from './MyComponent.js'
new Vue({
el: '#app',
components: {
MyComponent
}
})
When MyComponent is created, it should take the value of the "style" property and add it to the DOM like this. Any ideas would be much appreciated.
$('body').append('<style>' + STYLE + '</style>')
Here is a plugin using Vue.component() function. But I don't want to use the component function.