Vue: Complex template syntax replacement with computed property OR Accessing pageContext from script #772
-
Hello! I banged my head against the wall for the past hour or so; and out popped this:
which results in a paragraph with the desired URL followed by an image sourced from the same URL. I would like to replace this with a computed property for syntactic sugar reasons. But more importantly, I'll need access to the Unfortunately I can't seem to figure out how to access the pageProps nor the pageContext from the Vue setup script. Is such a thing possible? I do hope this is the correct place for this question. Thank you! Your code is amazing! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
A thought: I could put the necessary data in a tag in the head, correct? And then access it from the script. test Oooh I'd still like to access the pageContext/pageProps/ edit: well, a tag in the body. Whatever |
Beta Was this translation helpful? Give feedback.
-
It works! I'd still like to know a way to directly access the pageProps from within the script; so I'll not mark this as answered yet. However, I've gotten my data to the script's <template>
<meta itemprop="collage" :content="JSON.stringify(post.collage)">
<meta itemprop="images" :content="JSON.stringify(post.images)">
<h1>{{ post.title }}</h1>
</template>
<script lang="ts">
const pageProps = ['post']
export default { props: pageProps }
</script>
<script setup lang="ts">
import { onMounted } from 'vue'
onMounted(() => {
let collage = document.body.querySelector("meta[itemprop='collage']").content
let images = document.body.querySelector("meta[itemprop='images']").content
console.log(collage)
console.log(images)
})
</script> |
Beta Was this translation helpful? Give feedback.
-
I believe https://vite-plugin-ssr.com/pageContext-anywhere is what you're looking for. |
Beta Was this translation helpful? Give feedback.
I believe https://vite-plugin-ssr.com/pageContext-anywhere is what you're looking for.