Маленькие тестовые компоненты:
<template>
<div
id="report-chart"
v-if="report"
></div>
<div v-else>
Loading...
</div>
</template>
<script>
import ReportChart from '@/components/report-chart'
export default {
data () {
return {
report: null
}
},
watch: {
report (value) {
if (value) this.showReport()
}
},
methods = {
showReport () {
// I expect the 'report-chart' elem exists but Im wrong.
console.log(document.getElementById('report-chart')) // -> null
},
loadReport () {
// returns Promise
}
},
mounted () {
this.loadReport().then(data => (this.report = data))
}
}
</script>
Когда я вызываю console.log (), я ожидаю, что элемент 'report-chart' отображается, но не ошибается.Зачем?Все необходимые триггеры включены, и DIV должен быть в документе.