業務需求是他要在頁面寫h5頁面代碼 而我從后臺拿回來這個代碼渲染上去 他寫的函式要能實作呼叫 我想到用區域注冊組件 如果template后面直接寫代碼就能正常使用 但是這個代碼需要從后臺拿回來 但是 使用區域創建組件template內的系結變數報錯 我也使用過v-html方法 v-html不識別script標簽 v-html的事件也觸發不了外面的函式

<template>
<div class="hello">
<h1>
我是父組件
</h1>
<div class="parent" id="parent">
</div>
</div>
</template>
<script>
import Vue from 'vue'
var MyComponent = Vue.extend({
data: function () {
return {
urlId: '',
jsContent: '',
html: `<a @click="show(1)">我是大魔王</a>`
}
},
template: this.html,
methods: {
show (i) {
console.log(i)
}
}
})
var component = new MyComponent().$mount()
export default {
data () {
return {
}
},
methods: {
},
mounted () {
document.getElementById('parent').appendChild(component.$el)
}
}
</script>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/106712.html
標籤:HTML5
上一篇:關于ifream 嵌套頁面問題
