背景:
vueCli4中使用jsx方式注册一个全局公共组件,结果引用了elementUI组件报错
render(h) {
let html = `<el-tag>标签</el-tag>`
const com = Vue.extend({
template: `<div class="articleContent">${html}</div>`
})
return h(com, {})
}
vue.esm.js?a026:628 [Vue warn]: Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the “name” option.
在main.js中我确定一定以及肯定是引入了elementUI
- 所以猜测可能问题是render上下文不一样,目前也没有其他好办法,只能将elementUI在这个地方再注册一遍,等我进化了在回头想其他更好的解决办法吧
<script>
import Vue from "vue/dist/vue.esm.js"
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);
export default {
name: 'ArticleContent',
props: {
html: String
},
render(h) {
let html = `<el-tag>标签</el-tag>`
const com = Vue.extend({
template: `<div class="articleContent">${html}</div>`
})
return h(com, {})
}
};
</script>