[英]How to bind a dynamic html content in Vue vmodal
我需要将 HTML 数据绑定到 VueJS 弹出窗口。 我正在使用 bootstrap vue 来显示自定义弹出窗口。 我必须将一些动态 HTML 数据绑定到弹出窗口。 目前,它作为字符串类型绑定,也将 HTML 标签显示为内容。
import { BootstrapVue } from "bootstrap-vue";
import "bootstrap/dist/css/bootstrap.css";
import "bootstrap-vue/dist/bootstrap-vue.css";
Vue.use(BootstrapVue);
methods: {
AnnouncementEventClick(id, category) {
var full_description = null;
if (category == "announcement") {
this.AnnouncementList.forEach(function (announcement) {
if (announcement.id == id) {
full_description = announcement.announcementEvents.full_description;
}
});
}
this.desc = full_description;
this.$bvModal.show("modal-scrollable");
},
}
<template>
<div>
<b-modal id="modal-scrollable" scrollable hide-footer hide-header>
{{ desc }}
<b-button class="mt-3" block @click="$bvModal.hide('modal-scrollable')"
>OK</b-button
>
</b-modal>
</div>
</template>
代码中的“full_description”是我需要绑定的动态内容。
解决方案 :
<div>
{{ desc }}
</div>
methods: {
AnnouncementEventClick(id, category) {
var full_description = null;
if (category == "announcement") {
this.AnnouncementList.forEach(function (announcement) {
if (announcement.id == id) {
full_description = announcement.announcementEvents.full_description;
}
});
}
});
}
this.desc = full_description;
//this.$bvModal.show("modal-scrollable");
this.showMsgOk();
},
showMsgOk() {
const h = this.$createElement;
// Using HTML string
const description = h("div", {
class: ["modal-scrollable"],
domProps: { innerHTML: this.desc },
});
// We must pass the generated VNodes as arrays
this.$bvModal.msgBoxOk([description], {
buttonSize: "md",
centered: true,
size: "lg",
});
},
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.