My goal is to utilize Vue.js without the need for a build step, but I've encountered an issue with its lack of a style property.
To tackle this problem, I came up with the idea of creating a custom "style" property on my Vue component instance and dynamically injecting its content into the DOM upon component creation or mounting.
The challenge lies in figuring out how to implement this concept. After exploring the plugins documentation, I realized that I would likely need to develop a plugin that checks for the existence of a "style" property and inserts it into the DOM accordingly. Additionally, I prefer not to use the Vue.component() function as I aim to leverage ES6 import/export. Here's a visualization of the expected outcome:
// 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
}
})
Upon the creation of MyComponent, it should extract the value of the "style" property and incorporate it into the DOM, similar to the following approach. Any suggestions on how to achieve this are highly appreciated.
$('body').append('<style>' + STYLE + '</style>')
Included here is a reference to a plugin utilizing the Vue.component() function, which I'd prefer to avoid: