How to get data from key-value pairs in Vue.js
P粉418854048
P粉418854048 2023-09-02 19:38:37
0
1
401
<p>I use rails on the backend and vue.js on the frontend. I'm trying to print the error just in case. Under <code>.catch</code> I get an error like below but cannot get the message from it. Please help me solve this problem. </p> <pre class="brush:php;toolbar:false;">.catch(function (error) { debugger });</pre> <p>In the console, if I try <code>error.response.data.error</code> this returns <code>'{:message=>"Amount is less than the minimum value"} '</code> I can't figure out how I can get only the message. </p> <p>Wrong answer</p>
P粉418854048
P粉418854048

reply all(1)
P粉337385922

Your baclend is not serializing the object correctly. So the message is part of a string and not a JSON property. If you don't want to change you can use

const message = error.response.data.error.substring(
    str.indexOf('"') + 1, 
    str.lastIndexOf('"')
);
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!