Answer the question
In order to leave comments, you need to log in
How to get attributes from outerHTML as props when instantiating Vue?
In theory it should work like this:
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<div id="app" :sometext="'hello world'"></div>
<script type="text/javascript">
new Vue({
props: ['sometext'],
mounted: function () {
console.log(this.sometext)
}
}).$mount('#app')
</script>
beforeMount: function () {
this.sometext = this.$el.attributes.sometext.value
},
Answer the question
In order to leave comments, you need to log in
You are trying to hang vue directives on the root node in html, so it doesn't work. You can make it data-sometext="blabla", and then try to read the attributes of this DOM node through $el. Only this whole idea looks like a crutch, do you really need to send data to the root element? Inside components down the tree from the root component, props will work without problems.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question