Skip to content

Commit

Permalink
chore(#312): add wrappers example
Browse files Browse the repository at this point in the history
  • Loading branch information
Decipher committed Oct 30, 2021
1 parent 7936641 commit a2a0616
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 0 deletions.
10 changes: 10 additions & 0 deletions examples/nuxt/wrappers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# wrappers

This directory contains exaples of how to use Wrapper components and the wrapper property.


## Setup

```
yarn && yarn dev
```
15 changes: 15 additions & 0 deletions examples/nuxt/wrappers/components/druxt/entity/node/Page.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<template>
<div>
This is a DruxtWrapper: DruxtEntityNodePage.vue
</div>
</template>

<script>
export default {
druxt: {
query: {
schema: true
}
}
}
</script>
3 changes: 3 additions & 0 deletions examples/nuxt/wrappers/nuxt.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
buildModules: [['druxt-entity', { baseUrl: 'https://demo-api.druxtjs.org' }]]
}
11 changes: 11 additions & 0 deletions examples/nuxt/wrappers/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "wrappers",
"scripts": {
"dev": "nuxt dev"
},
"packageManager": "[email protected]",
"dependencies": {
"druxt-entity": "link:../../../packages/druxt-entity",
"nuxt": "latest"
}
}
49 changes: 49 additions & 0 deletions examples/nuxt/wrappers/pages/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<template>
<div v-if="!$fetchState.pending">
<details>
<summary><strong>Wrapper: default</strong></summary>
<DruxtEntity :type="type" :uuid="uuid" />
</details>

<details>
<summary><strong>Wrapper: false</strong></summary>
<DruxtEntity :type="type" :uuid="uuid" :wrapper="false" />
</details>

<details>
<summary><strong>Template injection / Wrapper: default</strong></summary>
<DruxtEntity :type="type" :uuid="uuid">
<template #default="{ entity }">
<pre><code>{{ JSON.stringify(entity, null, ' ') }}</code></pre>
</template>
</DruxtEntity>
</details>

<details>
<summary><strong>Template injection / Wrapper: true</strong></summary>
<DruxtEntity :type="type" :uuid="uuid" :wrapper="true">
<template #default="{ entity }">
<pre><code>{{ JSON.stringify(entity, null, ' ') }}</code></pre>
</template>
</DruxtEntity>
</details>
</div>

<div v-else>Loading...</div>
</template>

<script>
import { DrupalJsonApiParams } from 'drupal-jsonapi-params'
export default {
async fetch() {
const query = new DrupalJsonApiParams().addPageLimit(1).addFields(this.type, ['id'])
this.uuid = (await this.$store.dispatch('druxt/getCollection', { type: this.type, query })).data[0].id
},
data: () => ({
uuid: null,
type: 'node--page'
})
}
</script>
Empty file.

0 comments on commit a2a0616

Please sign in to comment.