'how to pass props to root App component in vuejs v3?
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: "-"
}
}
Solution 1:[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>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Boussadjra Brahim |
