Answer the question
In order to leave comments, you need to log in
How to embed vue component in html?
In general, the question is this. (Apache Echarts charts are used)
There is a chart.
The graph has corresponding points, over which hints appear when you hover.
The tooltip content is simply html text defined in one of the chart options:
let tooltip = `
Ask Price: ${params.value[0]}<br>
Duration: ${params.value[1]}
`;
//возвращаем подсказку чтобы отрисовать её
return tooltip
//this.showInfo - метод текущего компонента
let tooltip= `
<span @click="${this.showInfo}">Ask Price</span>: ${params.value[0]}<br>
Duration: ${params.value[1]}
`;
return tooltip
//в ModalInfo кроме слота больше ничего нет
import ModalInfo from '@/components/ModalInfo'
//...
let ComponentClass = Vue.extend(ModalInfo)
let tooltipInfo = new ComponentClass()
tooltipInfo.$slots.info = `
<span @click="${this.showInfo}">Ask Price</span>: ${params.value[0]}<br>
Duration: ${params.value[1]}
`;
tooltipInfo.$mount()
return tooltipInfo.$el
//...
Answer the question
In order to leave comments, you need to log in
Do you understand that ``
simple text is put in quotes , but this.showInfo
you have a function in it ?
This will never work.
Why does this work in .vue files inside <template>
? Because .vue is not .js, it's a separate file format using a separate templating microlanguage that compiles to js.
A simple, but bad, option is to use a regular html onclick pointing to a globally fumbled function.
A complex option - a complex one, you need to think and first deal with echarts - maybe something simpler can be created.
...upd:
Yes, you can make it easier if you read the docs :
No text needed, tooltip formatter can return HTMLElement and HTMLElement[].
So you can just do something like this:
formatter: (params) => {
const span = document.createElement('span');
span.onclick = this.showInfo;
span.textContent = 'Ask Price';
return [
span,
document.createTextNode(`: ${params.value[0]}`),
document.createElement('br'),
document.createTextNode(`Duration: ${params.value[1]}`),
]
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question