I want to dynamically set html tags for components. For instance:
components: {
test: {
props: ['tag', 'attributes'],
render(createElement) {
return createElement(this.tag || 'div', {attrs: this.attributes || {}}, this.$slots.default);
}
}
}
Then I can use this code in the html file:
<test tag="a" :attributes="{href:'http://www.google.com'}">a tag content</test>
<test tag="p">p tag content</test>
Now, what I want to do is to separate my components using something like Vue Loader. Basically, I want to split my different components into different files, and then import them using the main.js.
I tried something like this, but it does not work:
export default {
components: {
test: {
props: ['tag', 'attributes'],
render(createElement) {
return createElement(this.tag || 'div', {attrs: this.attributes || {}}, this.$slots.default);
}
}
}
}
import Vue from 'vue'
import Test from './components/Test.js'
new Vue({
el: '#app',
components: {
Test
}
})
This does not work.
Any idea how to make it work?
thank
Moshe source
share