- Inject
$fakerto the context everywhere.
- Add
faker-nuxtdependency to your project
npm install --save-dev faker-nuxt # or yarn add --dev faker-nuxt- Add
faker-nuxtto thebuildModulessection ofnuxt.config.js
export default {
buildModules: [
// Simple usage
'faker-nuxt',
// With options
['faker-nuxt', { /* module options */ }]
]
}dependency (No --dev or --save-dev flags) and use modules section in nuxt.config.js instead of buildModules.
export default {
buildModules: [
'faker-nuxt'
],
faker: {
/* module options */
}
}You can set a default locale via the locale option.
export default {
buildModules: [
'faker-nuxt'
],
faker: {
locale: 'pt_BR',
}
}You can set a default seed via the seed option.
export default {
buildModules: [
'faker-nuxt'
],
faker: {
seed: 'Banana123',
}
}<div>{{ $faker.lorem.word() }}</div>
<div v-text="$faker.lorem.words()"></div><script>
export default {
data() {
return {
name: this.$faker.fake('{{name.lastName}}, {{name.firstName}} {{name.suffix}}')
}
}
}
</script>