Home>
Vux environment is built with Nuxt.js.
When I put a value in the input field and press the button, I want to write it as json data and write it to a file.
The error "fs.writeFileSync is not a function" appears and the file cannot be exported.
# pages/index.vue
<template>
<form action = "/ thanks" method = "post">
<section>
(1) Enter your name.
<input v-model = "yourName" type = "text">
</section>
<section>
(2) Enter the message.
<textarea v-model = "yourMessage" />
</section>
<input type = "submit" value = "send" @ click = "exportMessage">
</form>
</template>
<script>
export default {
data () {
return {
yourName: '',
yourMessage: ''
}
},
methods: {
exportMessage () {
const fs = require ('fs')
const data = {
yourName: this.yourName,
yourMessage: this.yourMessage
}
fs.writeFileSync ('test.json', JSON.stringify (data))
}
}
}
</script>
The code is currently in the above state.
When you use "fs.writeFileSync", you shouldn't write inmethod
, but I don't know how to do it.
-
Answer # 1
Related articles
- vuejs - in nuxtjs, created is not executed when the screen is changed using
- vuejs - realization of inject in nuxtjs
- vuejs - nuxtjs data () value is not updated (looks like)
- Vuejs + Nuxtjs project using Vee-validate form validation
- vuejs - nuxtjs ignore (is there a way to ignore your own tags)
- vuejs - dom operation is performed when jquery is used in nuxtjs, but i want to disable the lifecycle methods (updated/beforeupd
- vuejs - nuxtjs, object error when displaying ie11
- vuejs - how to set full screen background color in nuxtjs
- vuejs - [nuxtjs] about using other js libraries
- javascript - can't get video time using video tag in vuejs (nuxtjs)
- vuejs - about blogging with nuxtjs + contentful + netlify
- vuejs - implement a text area like twitter in nuxtjs
- vuejs - unable to get api from axios in nuxtjs vuex store
- vuejs - [nuxtjs] i want to display the data of firestore acquired by computed with v-for
- is it possible to send the value that can be obtained with vuejs in the form of laravel? (without axios)
- php - i want to pass a column name string in nuxtjs vuejs and refer to a variable
- vuejs - multilingual with nuxtjs
- vuejs - i want to load adobe fonts with nuxtjs
- vuejs - i want to reflect what i typed in nuxtjs
- vuejs - how can i make a word-of-mouth function with nuxtjs?
Trends
fs is a Node.js file module. Vue is JavaScript on the web, so you can't use it.
Using web file modules
Or you can pass information to Express etc. and save it on the server side.