失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > vue 给iframe设置src_使用不带src属性的vuejs在iframe中渲染组件

vue 给iframe设置src_使用不带src属性的vuejs在iframe中渲染组件

时间:2022-01-02 18:38:42

相关推荐

vue 给iframe设置src_使用不带src属性的vuejs在iframe中渲染组件

I want to render component in this iframe. Is there any option of creating html element or rendering component in iframe?

new Vue({

el:'#frame',

store:store,

router:router,

render: component

})

解决方案

You can refer below link That helped me a lot.

Here is the link and the code snippets.

ponent('i-frame', {

render(h) {

return h('iframe', {

on: { load: this.renderChildren }

})

},

beforeUpdate() {

//freezing to prevent unnessessary Reactifiation of vNodes

this.iApp.children = Object.freeze(this.$slots.default)

},

methods: {

renderChildren() {

const children = this.$slots.default

const body = this.$el.contentDocument.body

const el = document.createElement('DIV') // we will mount or nested app to this element

body.appendChild(el)

const iApp = new Vue({

name: 'iApp',

//freezing to prevent unnessessary Reactifiation of vNodes

data: { children: Object.freeze(children) },

render(h) {

return h('div', this.children)

},

})

iApp.$mount(el) // mount into iframe

this.iApp = iApp // cache instance for later updates

}

}

})

ponent('test-child', {

template: `

{{ title }}

`,

props: ['title'],

methods: {

log: _.debounce(function() {

console.log('resize!')

}, 200)

},

mounted() {

this.$nextTick(() => {

const doc = this.$el.ownerDocument

const win = doc.defaultView

win.addEventListener('resize', this.log)

})

},

beforeDestroy() {

const doc = this.$el.ownerDocument

const win = doc.defaultView

win.removeEventListener('resize', this.log)

}

})

new Vue({

el: '#app',

data: {

dynamicPart: 'InputContent',

show: false,

}

})

如果觉得《vue 给iframe设置src_使用不带src属性的vuejs在iframe中渲染组件》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。