Created
October 7, 2018 11:29
-
-
Save cossssmin/2947009b1e116c1a684a9056bd3cf2dc to your computer and use it in GitHub Desktop.
Vue.js render textarea HTML in iframe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="app"> | |
<div class="flex flex-wrap h-screen"> | |
<editor target="preview" class="w-full lg:w-2/5 p-4 font-mono bg-grey-lightest outline-none resize-none"></editor> | |
<iframe id="preview" class="w-full lg:w-3/5 bg-graph-paper"></iframe> | |
</div> | |
</div> | |
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Vue.component("editor", { | |
props: { | |
placeholder: { | |
type: String, | |
required: false, | |
default: 'Paste in some HTML...' | |
}, | |
target: { | |
type: String, | |
required: true | |
} | |
}, | |
data: function() { | |
return {}; | |
}, | |
mounted: function() { | |
}, | |
methods: { | |
setSrcdoc: function() { | |
let iframe = document.getElementById(this.target); | |
iframe.srcdoc = this.$el.value; | |
} | |
}, | |
render: function(createElement) { | |
return createElement( | |
'textarea', | |
{ | |
domProps: { | |
placeholder: this.placeholder | |
}, | |
on: { | |
input: this.setSrcdoc | |
} | |
} | |
); | |
} | |
}); | |
new Vue({ | |
name: "vue-textarea-iframe", | |
el: "#app" | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment