[英]Render vue component in data
I trying to make custom tooltip for apexcharts like in example: https://apexcharts.com/docs/options/tooltip/#我试图为顶点图表制作自定义工具提示,例如: https://apexcharts.com/docs/options/tooltip/#
tooltip: {
custom: function({series, seriesIndex, dataPointIndex, w}) {
return '<div class="arrow_box">' +
'<span>' + series[seriesIndex][dataPointIndex] + '</span>' +
'</div>'
}
}
and it's works, but when I set in return some vue component nothing shows.它可以工作,但是当我返回一些 vue 组件时,什么也没显示。
tooltip: {
custom: function({series, seriesIndex, dataPointIndex, w}) {
return '<MyComponent/>'
}
}
<template>
<div>Just simple component</div>
</template>
<script>
export default { name: "MyComponent" }
</script>
Why is this happening and how to fix it?为什么会发生这种情况以及如何解决?
To make Vue render the component correctly, you'll have to tell it to in the custom tooltip function:要使 Vue 正确渲染组件,您必须在自定义工具提示 function 中告诉它:
tooltip: {
custom: ({series, seriesIndex, dataPointIndex, w}) => {
// create component constructor
var TooltipComponent = Vue.extend({
template: '<my-component/>'
});
// create an instance of tooltip and mount it
var tooltip = new TooltipComponent();
tooltip.$mount();
// Return the html
return tooltip.$el.outerHTML;
}
}
If you need data or other reactivity it becomes a bit more complicated, see https://v2.vuejs.org/v2/api/#Vue-extend for more information.如果您需要数据或其他反应性,它会变得有点复杂,请参阅https://v2.vuejs.org/v2/api/#Vue-extend了解更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.