Reputation: 77
How can i pass some variable from the main div folder:
<div
id="app"
someVariable='some value'
></div>
and to have it as a prop in the main App component in VueJS v3.0:
name: "App",
components: {
},
props: {
someVariable: {
type: String,
default: "-"
}
}
Upvotes: 1
Views: 2035
Reputation: 1
You could not access that using props, but you could get the value of that attribute using some Vanilla js DOM like document.getElementById("app").getAttribute("someVariable")
const {
createApp
} = Vue;
const App = {
props: ["someVariable"],
data() {
return {
}
},
mounted() {
console.log(document.getElementById("app").getAttribute("someVariable"))
}
}
const app = createApp(App)
app.mount('#app')
<script src="https://unpkg.com/[email protected]/dist/vue.global.prod.js"></script>
<div id="app" someVariable='some value'>
Vue 3 app
</div>
Upvotes: 2