Methods
All methods are attached to the component instance. If you are using TypeScript, you can import the NesVueInstance type supplied by nes-vue to get the instance’s type.
<script setup lang="ts">
import { ref } from 'vue'
import { NesVue } from 'nes-vue'
import type { NesVueInstance } from 'nes-vue'
const nes = ref<NesVueInstance>()
</script>
<template>
<nes-vue
ref="nes"
url="https://taiyuuki.github.io/nes-vue/Super Mario Bros (JU).nes"
/>
</template><script setup lang="ts">
import { ref } from 'vue'
import { NesVue } from 'nes-vue'
import type { NesVueInstance } from 'nes-vue'
const nes = ref<NesVueInstance>()
</script>
<template>
<nes-vue
ref="nes"
url="https://taiyuuki.github.io/nes-vue/Super Mario Bros (JU).nes"
/>
</template>start
Start NES game.
start(url?: string) => voidstart(url?: string) => voidTIP
In most cases, clicking on the text (label) in the middle of the screen will start the game without the start method.
WARNING
If you have to switch the game via the start method, you must use the v-model directive to bind the url, so that nes-vue can update it.
reset
Restart the game.
reset() => voidreset() => voidstop
Stop the game.
stop() => voidstop() => voidpause
The game is paused and can be resumed.
pause() => voidpause() => voidplay
Resume the game.
play() => voidplay() => voidsave
Save game state to localStorage or indexedDB by any id.
WARNING
Can only be loaded while the game is running, and ensure that the running game is consistent with the saved game.
save(id: string) => voidsave(id: string) => voidBy default, the game state is saved in indexedDB, you can also save it in localStorage via storage property.
Each game state archive requires about 200KB, if you need to save more data, it’s recommended to use indexedDB.
load
Load game state.
load(id: string) => voidload(id: string) => voidexample:
<script setup>
import { ref } from 'vue'
import { NesVue } from 'nes-vue'
const nes = ref()
const id = 'example'
function save() {
// save state
nes.value.save(id)
}
function load() {
// load state
nes.value.load(id)
}
</script>
<template>
<nes-vue
ref="nes"
url="https://taiyuuki.github.io/nes-vue/Super Mario Bros (JU).nes"
width="512"
height="480"
/>
<button @click="save">Save</button>
<button @click="load">Load</button>
</template><script setup>
import { ref } from 'vue'
import { NesVue } from 'nes-vue'
const nes = ref()
const id = 'example'
function save() {
// save state
nes.value.save(id)
}
function load() {
// load state
nes.value.load(id)
}
</script>
<template>
<nes-vue
ref="nes"
url="https://taiyuuki.github.io/nes-vue/Super Mario Bros (JU).nes"
width="512"
height="480"
/>
<button @click="save">Save</button>
<button @click="load">Load</button>
</template><script setup lang="ts">
import type { Ref } from 'vue'
import type { NesVueInstance } from 'nes-vue'
import { ref } from 'vue'
import { NesVue } from 'nes-vue'
const nes = ref() as Ref<NesVueInstance>
const id = 'example'
function save() {
// save state
nes.value.save(id)
}
function load() {
// load state
nes.value.load(id)
}
</script>
<template>
<nes-vue
ref="nes"
url="https://taiyuuki.github.io/nes-vue/Super Mario Bros (JU).nes"
width="512"
height="480"
/>
<button @click="save">Save</button>
<button @click="load">Load</button>
</template><script setup lang="ts">
import type { Ref } from 'vue'
import type { NesVueInstance } from 'nes-vue'
import { ref } from 'vue'
import { NesVue } from 'nes-vue'
const nes = ref() as Ref<NesVueInstance>
const id = 'example'
function save() {
// save state
nes.value.save(id)
}
function load() {
// load state
nes.value.load(id)
}
</script>
<template>
<nes-vue
ref="nes"
url="https://taiyuuki.github.io/nes-vue/Super Mario Bros (JU).nes"
width="512"
height="480"
/>
<button @click="save">Save</button>
<button @click="load">Load</button>
</template>remove
Remove game state.
remove(id: string) => voidremove(id: string) => voidclear
Clear all saved state.
clear() => voidclear() => voidgetCurrentData
Retrieve the raw save data so you can store it anywhere you like.
interface SavedData {
hash: string
data: Uint8Array
}
getCurrentData() => SavedData | nullinterface SavedData {
hash: string
data: Uint8Array
}
getCurrentData() => SavedData | nullloadGameData
Load raw save data created with getCurrentData .
loadGameData(savedData: SavedData) => voidloadGameData(savedData: SavedData) => voidscreenshot
screenshot(download?: boolean, imageName?: string) => HTMLImageElementscreenshot(download?: boolean, imageName?: string) => HTMLImageElementscreenshot(true) will start downloading the screenshot inside the browser.
The return value is an image element of the screenshot.
fm2URL
fm2URL(url: string) => Promise<fm2Play>fm2URL(url: string) => Promise<fm2Play>Fetch the *.fm2 file, refer to Replay.
fm2Text
fm2Text(text: string) => Promise<fm2Play>fm2Text(text: string) => Promise<fm2Play>Read the *.fm2 file's text content, refer to Replay.
fm2Play
fm2Play() => voidfm2Play() => voidPlay fm2 video, refer to Replay.
fm2Stop
fm2Stop() => voidfm2Stop() => voidStop fm2 video, refer to Replay.
cheatCode
cheatCode(code: string) => voidcheatCode(code: string) => voidEnable cheat code, refer to Cheat Code.
cancelCheatCode
cancelCheatCode(code: string) => voidcancelCheatCode(code: string) => voidDisable cheat code, refer to Cheat Code.
cancelCheatCodeAll
cancelCheatCodeAll() => voidcancelCheatCodeAll() => voidDisable all cheat code, refer to Cheat Code.