1.编写一段nodejs代码
const fs = require('fs')//引入模块
const data = [{ name: '小明' }, { name: '小白' }]//定义一个数组
fs.writeFileSync('data.txt', data)//将数组保存在data.txt文件中
2.在小黑窗看错误提示
错误提示
TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string
or an instance of Buffer, TypedArray, or DataView. Received an instance of Array
“data”参数必须是string类型或Buffer、TypedArray或DataView的实例。收到数组的一个实例"
由错误提示可以知道data参数必须是字符串类型或Buffer、TypedArray或DataView的实例。收到数组的一个实例
所以我们将data中的数组转换成字符串类型
代码如下:
const fs = require('fs')
const data = [{ name: '小明' }, { name: '小白' }]
//JSON.stringify()将data转换成字符串类型
fs.writeFileSync('data.txt', JSON.stringify(data))
总结:不能穿数组或者对象,不然就会报错.
密码错误并且页面跳转,没发送ajax请求数据,导致页面跳转.
没有写return 没有返回值,打印出来一个空数组.