Skip to content

Commit

Permalink
add Post.vue example using data attributes for props
Browse files Browse the repository at this point in the history
  • Loading branch information
vcavallo committed Aug 9, 2023
1 parent 0306d57 commit 5b306e2
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
8 changes: 8 additions & 0 deletions _frontend/entrypoints/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,13 @@ import '~/src/assets/index.scss'

import { createApp } from 'vue'
import App from '~/src/App.vue'
import Post from '~/src/Post.vue'

createApp(App).mount('#app')

const postElement = document.querySelector('#post')
const title = postElement.dataset.title
const post = createApp(Post, {
title
});
post.mount('#post')
22 changes: 22 additions & 0 deletions _frontend/src/Post.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<script setup lang="ts">
import { ref } from 'vue'
const test = ref('hello world')
const props = defineProps<{
title: string;
}>()
</script>

<template>

<main>
This is vue
<pre>
hi: {{ test }}
title: {{ title }}
</pre>

</main>
</template>
1 change: 0 additions & 1 deletion _layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@
<body>
{% include navigation.html %}
{{ content }}
<div id="app"></div>
</body>
</html>
2 changes: 2 additions & 0 deletions _layouts/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ <h1>{{ page.title }}</h1>
</p>

{{ content }}

<div id="post" data-title="{{ page.title }}"></div>
1 change: 1 addition & 0 deletions index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ title: Home
---

<h1>Test Hello</h1>

**this is bold in markdown**

<ul>
Expand Down

0 comments on commit 5b306e2

Please sign in to comment.