vue 在字符串中添加div标签赋予样式并添加点击事件
有个需求在解释中给元素添加样式与点击事件
data() {
return {
explanation: `<span>* 说明:非全日制学历需要提前认证电子备案注册表,点击<span style='color: rgba(5, 103, 216, 1); cursor: pointer; text-decoration:underline;margin: 0 3px' onclick=educationClick()>学历认证</span>查看操作方法<div>`
}
}
<div class="condition-explanation">
<!--{{ explanation }}-->
<div v-html="explanation" />
</div>
刚开始想直接赋值,后来发现不好用,然后用了下v-html
mounted() {
window.educationClick = this.educationClick;
}
methods: {
// 学历查看
educationClick() {
console.log("查看学历");
},
}
直接调用不好使,需要在mounted中给方法赋值一下。