In vue3, when the data format returned by the backend is "{"url":"https:..."}", the data echo problem

1. When the data format returned by the backend is "{"url":"https://...."}", we need to use JSON.parse to convert the data format to complete the data echo

But if you use JSON.parse directly, it is very likely that the following error will be reported

2. We can use try catch to capture to avoid error reporting

function parseJson(str) {
  try {
    return JSON.parse(str);
  } catch (e) {
    return {};
  }
}

3. The method parseJson() can be directly introduced in html

<img :src="parseJson(userInfo?.signUrl).url" />

Guess you like

Origin blog.csdn.net/m0_52761651/article/details/130014316