File tree Expand file tree Collapse file tree 6 files changed +71
-9
lines changed
Expand file tree Collapse file tree 6 files changed +71
-9
lines changed Original file line number Diff line number Diff line change 1+ import { defineNuxtPlugin , useNuxtApp } from '#imports' ;
2+
3+ export default defineNuxtPlugin ( ( ) => {
4+ const { $store } = useNuxtApp ( ) ;
5+
6+ if ( process . server ) {
7+ $store . dispatch ( 'increment' ) ;
8+ }
9+ } ) ;
Original file line number Diff line number Diff line change 1- import { describe , it , expect } from 'vitest'
2- import { fileURLToPath } from 'node:url'
3- import { setup , $fetch } from '@nuxt/test-utils'
1+ import { describe , it , expect } from 'vitest' ;
2+ import { fileURLToPath } from 'node:url' ;
3+ import { setup , $fetch } from '@nuxt/test-utils' ;
44
55describe ( 'ssr' , async ( ) => {
66 await setup ( {
77 rootDir : fileURLToPath ( new URL ( './fixtures/basic' , import . meta. url ) ) ,
8- } )
8+ } ) ;
99
1010 it ( 'renders the index page' , async ( ) => {
1111 // Get response to a server-rendered page with `$fetch`.
12- const html = await $fetch ( '/' )
13- expect ( html ) . toContain ( '<div>basic</div>' )
14- } )
15- } )
12+ const html = await $fetch ( '/' ) ;
13+
14+ expect ( html ) . toContain ( '<div>count: 0</div>' ) ;
15+ expect ( html ) . toContain ( '<div>server: 1</div>' ) ;
16+ } ) ;
17+ } ) ;
Original file line number Diff line number Diff line change 11<template >
2- <div >basic</div >
2+ <div >count: {{ $store.state.count }}</div >
3+ <div >server: {{ $store.state.server.count }}</div >
34</template >
45
56<script setup>
7+ import { useNuxtApp } from ' #imports' ;
8+
9+ const { $store } = useNuxtApp ();
610 </script >
Original file line number Diff line number Diff line change 1+ import { defineNuxtPlugin , useNuxtApp } from '#imports' ;
2+
3+ export default defineNuxtPlugin ( ( ) => {
4+ const { $store } = useNuxtApp ( ) ;
5+
6+ if ( process . server ) {
7+ $store . dispatch ( 'server/increment' ) ;
8+ }
9+ } ) ;
Original file line number Diff line number Diff line change 1+ export type IndexState = {
2+ count : number ;
3+ } ;
4+
5+ export const state = ( ) => ( {
6+ count : 0 ,
7+ } ) ;
8+
9+ export const mutations = {
10+ increment ( state : IndexState ) {
11+ state . count ++ ;
12+ } ,
13+ } ;
14+
15+ export const actions = {
16+ increment ( { commit } : { commit : any } ) {
17+ commit ( 'increment' ) ;
18+ } ,
19+ } ;
Original file line number Diff line number Diff line change 1+ type CountState = {
2+ count : number ;
3+ } ;
4+
5+ export const state = ( ) => ( {
6+ count : 0 ,
7+ } ) ;
8+
9+ export const mutations = {
10+ increment ( state : CountState ) {
11+ state . count ++ ;
12+ } ,
13+ } ;
14+
15+ export const actions = {
16+ increment ( { commit } : { commit : any } ) {
17+ commit ( 'increment' ) ;
18+ } ,
19+ } ;
You can’t perform that action at this time.
0 commit comments