Closed richardfrench closed 3 years ago
So the below seems to produce more promising results. It generates 3 pages, as there are 3 users in my data file. Leaving off the permalink property makes the URLs based on their index. Trying to append user.name or indeed any other user property to the end of the permalink string doesn't seem to work. Have I got the right idea?
<template>
<div>
<p v-html="test"></p>
{{user.name}}
</div>
</template>
<script>
export default {
data: () => {
return {
permalink:"/user/" + Math.random(),
test: "HELLO",
pagination: {
data: "userList",
size: 1,
alias: "user"
},
};
},
}
</script>
I've not tested this code, but you could try:
The 11ty permalink is a funny one as, even though it's data, the 'data' is passed back into it (kinda like a computed property) so you can access you shortcodes/javascript functions with this
<script>
export default {
data: () => ({
test: "HELLO",
permalink() {
return `user/${this.slug(this.user.name)}/`
},
pagination: {
data: 'userList',
size: 1,
alias: 'user',
}
})
}
</script>
Kinda off-topic, but I personally think it'd better for this eleventy plugin to extend Vue as well with an eleventy
object rather than merging it all in with data, something like:
<script>
export default {
data: () => ({
test: "HELLO",
}),
eleventy: () => ({
title({ article }) => article.title,
permalink({ article }) => article.slug,
pagination: {
data: 'articles',
size: 1,
alias: 'article',
}
})
}
</script>
...I dunno.
Paginating with Vue for Page Templates works for me by passing a function argument to the permalink function as shown below. The argument passed to the function seems to contain the global 11ty data object for your page. Hope this works for you as well.
<script>
export default {
data: () => ({
permalink(data) {
return `articles/${data.article.slug}/`
},
pagination: {
data: 'articles',
size: 1,
alias: 'article',
}
})
}
</script>
Hey sorry for the late reply here. I just did find an example of this working in our codebase.
I think the original mistake was that pagination.data
needs to be a string. A little confusing when you’re looking at it from YAML on the docs, I’d agree https://www.11ty.dev/docs/pagination/#paging-an-array
This is an automated message to let you know that a helpful response was posted to your issue and for the health of the repository issue tracker the issue will be closed. This is to help alleviate issues hanging open waiting for a response from the original poster.
If the response works to solve your problem—great! But if you’re still having problems, do not let the issue’s closing deter you if you have additional questions! Post another comment and I will reopen the issue. Thanks!
Think what you've come up with looks really great. I've tried the above, but I get an error. That's the standard pagination you might use in an njk file, for example.
Am I doing it wrong, or is pagination not currently supported? Is there another way of achieving it? We currently use Nunjucks for our 11ty product at work, and I'm keen to use Vue instead.
Thanks!