mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 00:23:53 +00:00
chore: add examples directory (#115)
This commit is contained in:
parent
5aa59c2ca5
commit
ca466e08a1
@ -1,6 +1,7 @@
|
||||
{
|
||||
"globals": {
|
||||
"NodeJS": true
|
||||
"NodeJS": true,
|
||||
"$fetch": true
|
||||
},
|
||||
"plugins": ["jsdoc"],
|
||||
"extends": [
|
||||
|
4
examples/async-data/nuxt.config.ts
Normal file
4
examples/async-data/nuxt.config.ts
Normal file
@ -0,0 +1,4 @@
|
||||
import { defineNuxtConfig } from '@nuxt/kit'
|
||||
|
||||
export default defineNuxtConfig({
|
||||
})
|
12
examples/async-data/package.json
Normal file
12
examples/async-data/package.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "example-async-data",
|
||||
"private": true,
|
||||
"devDependencies": {
|
||||
"nuxt3": "^0.5.1"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "nu dev",
|
||||
"build": "nu build",
|
||||
"start": "node .output/server"
|
||||
}
|
||||
}
|
19
examples/async-data/pages/index.vue
Normal file
19
examples/async-data/pages/index.vue
Normal file
@ -0,0 +1,19 @@
|
||||
<template>
|
||||
<div>
|
||||
Page visits: {{ data.count }}
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineNuxtComponent, asyncData } from '@nuxt/app'
|
||||
|
||||
export default defineNuxtComponent({
|
||||
setup () {
|
||||
const { data } = asyncData('time', () => $fetch('/api/count'))
|
||||
|
||||
return {
|
||||
data
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
3
examples/async-data/server/api/count.js
Normal file
3
examples/async-data/server/api/count.js
Normal file
@ -0,0 +1,3 @@
|
||||
let ctr = 0
|
||||
|
||||
export default () => ({ count: ++ctr })
|
5
examples/hello-world/app.vue
Normal file
5
examples/hello-world/app.vue
Normal file
@ -0,0 +1,5 @@
|
||||
<template>
|
||||
<div>
|
||||
Hello Nuxt!
|
||||
</div>
|
||||
</template>
|
4
examples/hello-world/nuxt.config.ts
Normal file
4
examples/hello-world/nuxt.config.ts
Normal file
@ -0,0 +1,4 @@
|
||||
import { defineNuxtConfig } from '@nuxt/kit'
|
||||
|
||||
export default defineNuxtConfig({
|
||||
})
|
12
examples/hello-world/package.json
Normal file
12
examples/hello-world/package.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "example-hello-world",
|
||||
"private": true,
|
||||
"devDependencies": {
|
||||
"nuxt3": "^0.5.1"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "nu dev",
|
||||
"build": "nu build",
|
||||
"start": "node .output/server"
|
||||
}
|
||||
}
|
12
examples/pages/app.vue
Normal file
12
examples/pages/app.vue
Normal file
@ -0,0 +1,12 @@
|
||||
<template>
|
||||
<div>
|
||||
<NuxtLink to="/">
|
||||
Home
|
||||
</NuxtLink>
|
||||
<NuxtLink to="/about">
|
||||
About
|
||||
</NuxtLink>
|
||||
|
||||
<NuxtPage />
|
||||
</div>
|
||||
</template>
|
4
examples/pages/nuxt.config.ts
Normal file
4
examples/pages/nuxt.config.ts
Normal file
@ -0,0 +1,4 @@
|
||||
import { defineNuxtConfig } from '@nuxt/kit'
|
||||
|
||||
export default defineNuxtConfig({
|
||||
})
|
12
examples/pages/package.json
Normal file
12
examples/pages/package.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "example-pages",
|
||||
"private": true,
|
||||
"devDependencies": {
|
||||
"nuxt3": "^0.5.1"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "nu dev",
|
||||
"build": "nu build",
|
||||
"start": "node .output/server"
|
||||
}
|
||||
}
|
5
examples/pages/pages/about.vue
Normal file
5
examples/pages/pages/about.vue
Normal file
@ -0,0 +1,5 @@
|
||||
<template>
|
||||
<div>
|
||||
About
|
||||
</div>
|
||||
</template>
|
5
examples/pages/pages/index.vue
Normal file
5
examples/pages/pages/index.vue
Normal file
@ -0,0 +1,5 @@
|
||||
<template>
|
||||
<div>
|
||||
Home
|
||||
</div>
|
||||
</template>
|
5
examples/with-vite/app.vue
Normal file
5
examples/with-vite/app.vue
Normal file
@ -0,0 +1,5 @@
|
||||
<template>
|
||||
<div>
|
||||
Hello Nuxt+Vite!
|
||||
</div>
|
||||
</template>
|
5
examples/with-vite/nuxt.config.ts
Normal file
5
examples/with-vite/nuxt.config.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import { defineNuxtConfig } from '@nuxt/kit'
|
||||
|
||||
export default defineNuxtConfig({
|
||||
vite: true
|
||||
})
|
12
examples/with-vite/package.json
Normal file
12
examples/with-vite/package.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "example-with-vite",
|
||||
"private": true,
|
||||
"devDependencies": {
|
||||
"nuxt3": "^0.5.1"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "nu dev",
|
||||
"build": "nu build",
|
||||
"start": "node .output/server"
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@
|
||||
"license": "MIT",
|
||||
"workspaces": [
|
||||
"packages/*",
|
||||
"examples/*",
|
||||
"docs"
|
||||
],
|
||||
"scripts": {
|
||||
@ -12,6 +13,8 @@
|
||||
"docs": "yarn nu dev docs",
|
||||
"nu": "./node_modules/.bin/nu",
|
||||
"play": "yarn run nu dev playground",
|
||||
"example": "yarn workspace example-$0 dev",
|
||||
"example:build": "yarn workspace example-$0 build",
|
||||
"lint": "eslint --ext .vue,.ts,.js .",
|
||||
"test": "yarn lint && jest",
|
||||
"test:compat": "TEST_COMPAT=1 jest",
|
||||
|
@ -1,37 +0,0 @@
|
||||
<template>
|
||||
<div>
|
||||
<nuxt-link to="/">
|
||||
Home
|
||||
</nuxt-link>
|
||||
<h2>{{ $route.path }}</h2>
|
||||
<pre>{{ foo }}</pre>
|
||||
<pre>{{ bar }}</pre>
|
||||
<pre>{{ from }}</pre>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { defineNuxtComponent, asyncData } from '@nuxt/app'
|
||||
const waitFor = (ms = 0) => new Promise(resolve => setTimeout(resolve, ms))
|
||||
|
||||
export default defineNuxtComponent({
|
||||
setup () {
|
||||
const { data: foo } = asyncData('foo', async () => {
|
||||
await waitFor(500)
|
||||
return { foo: true }
|
||||
})
|
||||
const { data: bar } = asyncData('bar', async () => {
|
||||
await waitFor(500)
|
||||
return { bar: true }
|
||||
})
|
||||
|
||||
const { data: from } = asyncData('from', () => ({ from: process.server ? 'server' : 'client' }))
|
||||
|
||||
return {
|
||||
foo,
|
||||
bar,
|
||||
from
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
@ -1,39 +0,0 @@
|
||||
<template>
|
||||
<div>
|
||||
<nuxt-link to="/">
|
||||
Home
|
||||
</nuxt-link>
|
||||
<h2>{{ $route.path }}</h2>
|
||||
<pre>{{ foo }}</pre>
|
||||
<pre>{{ bar }}</pre>
|
||||
<pre>{{ from }}</pre>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { useAsyncData } from '@nuxt/app'
|
||||
const waitFor = (ms = 0) => new Promise(resolve => setTimeout(resolve, ms))
|
||||
|
||||
export default {
|
||||
async setup () {
|
||||
const asyncData = useAsyncData()
|
||||
|
||||
const { data: foo } = await asyncData('foo', async () => {
|
||||
await waitFor(500)
|
||||
return { foo: true }
|
||||
})
|
||||
const { data: bar } = await asyncData('bar', async () => {
|
||||
await waitFor(500)
|
||||
return { bar: true }
|
||||
})
|
||||
|
||||
const { data: from } = await asyncData('from', () => ({ from: process.server ? 'server' : 'client' }))
|
||||
|
||||
return {
|
||||
foo,
|
||||
bar,
|
||||
from
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
@ -1,28 +1,12 @@
|
||||
<template>
|
||||
<div>
|
||||
<h2>
|
||||
Hello world
|
||||
</h2>
|
||||
<strong>Playground pages</strong>
|
||||
<ul>
|
||||
<li v-for="link of links" :key="link">
|
||||
<nuxt-link :to="link">
|
||||
{{ link }}
|
||||
</nuxt-link>
|
||||
</li>
|
||||
</ul>
|
||||
...
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { defineComponent } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { defineNuxtComponent } from '@nuxt/app'
|
||||
|
||||
export default defineComponent({
|
||||
setup () {
|
||||
const links = useRouter().getRoutes().filter(route => ['index', '404'].includes(route.name) === false).map(route => route.path)
|
||||
|
||||
return { links }
|
||||
}
|
||||
export default defineNuxtComponent({
|
||||
})
|
||||
</script>
|
||||
|
32
yarn.lock
32
yarn.lock
@ -6190,6 +6190,38 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"example-async-data@workspace:examples/async-data":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "example-async-data@workspace:examples/async-data"
|
||||
dependencies:
|
||||
nuxt3: ^0.5.1
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"example-hello-world@workspace:examples/hello-world":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "example-hello-world@workspace:examples/hello-world"
|
||||
dependencies:
|
||||
nuxt3: ^0.5.1
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"example-pages@workspace:examples/pages":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "example-pages@workspace:examples/pages"
|
||||
dependencies:
|
||||
nuxt3: ^0.5.1
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"example-with-vite@workspace:examples/with-vite":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "example-with-vite@workspace:examples/with-vite"
|
||||
dependencies:
|
||||
nuxt3: ^0.5.1
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"exec-sh@npm:^0.3.2":
|
||||
version: 0.3.6
|
||||
resolution: "exec-sh@npm:0.3.6"
|
||||
|
Loading…
Reference in New Issue
Block a user