如何将一段html代码动态插入到vue的dom上?
我想将以下html代码动态插入到vue里:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Awesome go-echarts</title>
<script src="https://go-echarts.github.io/go-echarts-assets/assets/echarts.min.js"></script>
</head>
<body>
<div class="container">
<div class="item" id="LHBhijIvJRRa" style="width:900px;height:500px;"></div>
</div>
<script type="text/javascript">
"use strict";
let goecharts_LHBhijIvJRRa = echarts.init(document.getElementById('LHBhijIvJRRa'), "white");
let option_LHBhijIvJRRa = {"color":["#5470c6","#91cc75","#fac858","#ee6666","#73c0de","#3ba272","#fc8452","#9a60b4","#ea7ccc"],"legend":{"show":false},"series":[{"name":"Category A","type":"bar","waveAnimation":false,"renderLabelForZeroData":false,"selectedMode":false,"animation":false,"data":[{"value":177},{"value":247},{"value":128},{"value":273},{"value":242},{"value":62},{"value":247}]},{"name":"Category B","type":"bar","waveAnimation":false,"renderLabelForZeroData":false,"selectedMode":false,"animation":false,"data":[{"value":187},{"value":279},{"value":124},{"value":159},{"value":214},{"value":63},{"value":111}]}],"title":{"text":"My first bar chart generated by go-echarts","subtext":"It's extremely easy to use, right?"},"tooltip":{"show":false},"xAxis":[{"data":["Mon","Tue","Wed","Thu","Fri","Sat","Sun"]}],"yAxis":[{}]};
goecharts_LHBhijIvJRRa.setOption(option_LHBhijIvJRRa);
</script>
<style>
.container {margin-top:30px; display: flex;justify-content: center;align-items: center;}
.item {margin: auto;}
</style>
</body>
</html>
使用的是vue提供的 v-html, 其中options参数就是上面的html代码:
<template>
<span v-html="options"></span>
</template>
现在问题是, 运行后显示一片空白,也没有报错。不知道是哪里出了问题
问一下各位大神,应该如何动态的插入一段html代码到vue3中运行啊
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
v-html
原理是使用元素的innerHTML
属性。innerHTML
属性不支持使用script标签。可以将
script
单独引入,并通过eval
执行额外的script代码