How can I successfully pass JSON data via an HTML attribute in Vue.js?
<div id="app" data-number="2" data-json="{"name":"John", "age":30, "car":null}"></div>
In my main.js file
new Vue({
el: `#app`,
render: h => h(App,{
props:{
myNumber: this.dataset.number,
myData: this.dataset.json
}
})
})
When attempting to access the JSON data with console.log(this.dataset.number)
, the output is correct (2). However, when trying to access myData
, only a single curly brace ({) seems to be returned. How can I properly pass JSON data to the Vue instance?