Answer the question
In order to leave comments, you need to log in
How to get code of svg file in vue?
I tried to get svg using fetch, the code is displayed in the console, but when I try to insert it into html I get the string "[object Promise]", options like getFileContent(url).then(a=>{return a}) also do not work
async getFileContent(url) {
const response = await fetch(url, {});
const json = await response.text();
console.log(json)
return json;
}
Answer the question
In order to leave comments, you need to log in
You need to learn what async is, what is Promise
, what is async
\ await
. Without it, you won't go anywhere.
You need to do either this: or this . always returns . You have to wait for the 'a to complete one way or another.
If you do so - of course you have lies . This one is just starting execution and there is no data there. Data will probably arrive in it in an hour if you are on a modem.
It has nothing to do with Vue. this.svg = await getFileContent(url)
getFileContent(url).then(a => this.svg = a)
Promise
Promise
Promise
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question