如上图所示,没那么多废话,直接上代码
html中
<div id="app">
<div :html="tempHtml"></div>
</div>
vue中
new Vue({
el: '#app',
data() {
return {
tempHtml: ''
}
},
created() {
this.getHtml()
},
mounted() {
window.clickFun = this.clickFun;
},
methods: {
getHtml() {
let template = "<el-button type='primary' size='mini' @click='clickFun()'>查询</el-button>"
this.tempHtml = template;
},
clickFun() {
console.log(121212);
}
},
render(h) {
const com = Vue.extend({
template: eval('`' + this.tempHtml + '`')
});
return h(com, {});
}
})