我已经正确导入了mysql。 这是我的代码,在其中声明了构造函数内部的连接。
import mysql from 'mysql';
export class StepForm extends Component {
constructor() {
super();
this.state ={
step: 1,
// welcome
qNumber:1,
accountNumber:'',
amount:'',
txNumber:1,
postArray : []
}
const connection = mysql.createConnection({
host: 'localhost',
port: 3306,
user: 'root',
password: 'whil',
database: 'qany'
});
connection.connect();
console.log(connection);
}
保存我遇到的组件错误
TypeError: Net.createConnection is not a function
Connection.connect
C:/react_programs/q_any/node_modules/mysql/lib/Connection.js:74
71 | this._connectCalled = true;
72 |
73 | // Connect either via a UNIX domain socket or a TCP socket.
> 74 | this._socket = (this.config.socketPath)
| ^ 75 | ? Net.createConnection(this.config.socketPath)
76 | : Net.createConnection(this.config.port, this.config.host);
77 |
应该做什么?