// 字段null轉(zhuǎn)字符串
1.export function null2str(data) {
? ? for (let x in data) {
? ? ? ? if (data[x] === null) {
? ? ? ? ? ? // 如果是null 把直接內(nèi)容轉(zhuǎn)為 ''
? ? ? ? ? ? data[x] = "";
? ? ? ? } else {
? ? ? ? ? ? if (Array.isArray(data[x])) {
? ? ? ? ? ? ? ? // 是數(shù)組遍歷數(shù)組 遞歸繼續(xù)處理
? ? ? ? ? ? ? ? data[x] = data[x].map((z) => {
? ? ? ? ? ? ? ? ? ? return null2str(z);
? ? ? ? ? ? ? ? });
? ? ? ? ? ? }
? ? ? ? ? ? if (typeof data[x] === "object") {
? ? ? ? ? ? ? ? // 是json 遞歸繼續(xù)處理
? ? ? ? ? ? ? ? data[x] = null2str(data[x]);
? ? ? ? ? ? }
? ? ? ? }
? ? }
? ? return data;
}
//調(diào)用方法文章來源:http://www.zghlxwxcb.cn/news/detail-681985.html
2.null2str(data)文章來源地址http://www.zghlxwxcb.cn/news/detail-681985.html
到了這里,關(guān)于vue 對后端返回字段值為null的變成空字符串的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!