I like the idea of Petite-vue. However, I am unable to get the simplest things working, unfortunately I can not find many examples and tutorials for petite-vue online. Any recommendations for good resources?
Here I am simply trying to print the output of a json file. I ended up defining the json object after it did not work. But I am still not getting the items printed in the for loop. Any idea what might be the issue?
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<script src="https://unpkg.com/petite-vue" defer init></script>
</head>
<body>
<h1> show data here:</h1>
<div id="app">
<div v-for="(item, index) in items" :key="index">
<h2>{{ item.title }}</h2>
</div>
</div>
<script type="module">
import { createApp } from 'https://cdn.skypack.dev/petite-vue'
const jsonData = [
{ title: 'Title 1'},
{ title: 'Title 2'},
{ title: 'Title 3'}
]
createApp({
data() {
return {
items: []
}
},
mounted() {
this.items = jsonData
}
}).mount('#app')
</script>
</body>
</html>
2
Answers
The problem happens due to the duplicate imports. Either you can use:
or you need to use:
Also there’s no
data
in petite-vuecreateApp
. You need to additems
directly. Check following code:Some documentation here mounted hook is different, no data function …