Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.0k views
in Technique[技术] by (71.8m points)

mysql如何插入一个数组?(nodejs + vue)

表结构是这样的:
image.png
image.png

这两个字段存的是数组数据
前端每次发请求前都要转为string

// 数组=>string(前端代码)
this.ruleForm.contact = JSON.stringify(this.ruleForm.contact);
this.ruleForm.images = JSON.stringify(this.ruleForm.images);

拿到数据后又要JSON.parse()转换

如果不转换的话sql就会报错

感觉这样来回转换好麻烦,有好的解决方法么?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

typeorm 有个类型是, 会主动帮你把数组转化的
simple-array-column-type typeorm

别的没用过 不是很清楚了


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...