Skip to content

Commit

Permalink
fix(nuxt): pass options
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Aug 24, 2021
1 parent 76bf9f9 commit e584a86
Show file tree
Hide file tree
Showing 7 changed files with 7,507 additions and 456 deletions.
36 changes: 36 additions & 0 deletions examples/nuxt/components/HelloWorld.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<template>
<div>
<h3>{{ msg }}, {{ name }}</h3>
<button @click="inc">
Inc
</button>
<div>{{ count }} x 2 = {{ doubled }}</div>
<button @click="dec()" v-html="decText" />
</div>
</template>

<script setup lang="ts">
const props = withDefaults(defineProps<{ msg: string; name: string | number }>(), { msg: 'Hello' })
const emit = defineEmits(['update'])
const count = ref(0)
const doubled = computed(() => count.value * 2)
function inc() {
count.value += 1
}
function dec() {
count.value += 1
}
const decText = '<b>Dec</b>'
watch(count, value => emit('update', value))
</script>

<script lang="ts">
export default {
name: 'App'
}
</script>
12 changes: 12 additions & 0 deletions examples/nuxt/nuxt.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default {
buildModules: [
// we disable the type check and left it to `vue-tsc`
['@nuxt/typescript-build', { typeCheck: false }],
// @vue/composition-api support
'@nuxtjs/composition-api/module',
// <script setup> transformer
'unplugin-vue2-script-setup/nuxt',
// auto import
['unplugin-auto-import/nuxt', { imports: ['@vue/composition-api'] }],
],
}
24 changes: 24 additions & 0 deletions examples/nuxt/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "nuxt-example",
"private": true,
"scripts": {
"dev": "nuxt",
"build": "vue-tsc --noEmit && nuxt build",
"start": "nuxt start",
"generate": "nuxt generate"
},
"dependencies": {
"core-js": "^3.15.1",
"nuxt": "^2.15.7",
"vue": "^2.6.14"
},
"devDependencies": {
"@nuxt/types": "^2.15.8",
"@nuxt/typescript-build": "^2.1.0",
"@nuxtjs/composition-api": "^0.27.0",
"@vue/runtime-dom": "^3.2.4",
"vue-tsc": "^0.3.0",
"unplugin-vue2-script-setup": "^0.4.0",
"unplugin-auto-import": "workspace:*"
}
}
13 changes: 13 additions & 0 deletions examples/nuxt/pages/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<template>
<div>
<hello-world name="Vue 2" @update="onUpdate" />
</div>
</template>

<script setup lang="ts">
import HelloWorld from '../components/HelloWorld.vue'
function onUpdate(e: any) {
console.log(e)
}
</script>
35 changes: 35 additions & 0 deletions examples/nuxt/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"compilerOptions": {
"target": "ES2018",
"module": "ESNext",
"moduleResolution": "Node",
"lib": [
"ESNext",
"ESNext.AsyncIterable",
"DOM"
],
"esModuleInterop": true,
"skipLibCheck": true,
"allowJs": true,
"sourceMap": true,
"strict": true,
"noEmit": true,
"baseUrl": ".",
"paths": {
"~/*": [
"./*"
],
"@/*": [
"./*"
]
},
"types": [
"@types/node",
"@nuxt/types",
"unplugin-vue2-script-setup/types"
]
},
"exclude": [
"node_modules"
]
}

0 comments on commit e584a86

Please sign in to comment.