<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Vue | async data()]]></title><description><![CDATA[<p dir="auto">התחלתי אתמול ללמוד vue, והסתבכתי עכשיו.<br />
אני מנסה לקבל מידע מ-API דרך פונקציית data, ולא מצליח.<br />
אני לוקח את המידע עם fetch, ומקבל Promise.<br />
אם אני עושה ככה:</p>
<pre><code>const data = fetch(config.apiEndpoint + 'book/' + this.$route.params.name).then(res =&gt; res.json())
return {
  book: data.book
}
</code></pre>
<p dir="auto">data הוא undefined, כי המידע עוד לא התקבל.<br />
אם אני עושה את זה עם async / await, הפונקציה מחזירה Promise, וvue צריך שהפונקציה תחזיר object..<br />
מה עושים?</p>
]]></description><link>https://tchumim.com/topic/10599/vue-async-data</link><generator>RSS for Node</generator><lastBuildDate>Fri, 13 Mar 2026 20:00:42 GMT</lastBuildDate><atom:link href="https://tchumim.com/topic/10599.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 27 Jan 2021 06:18:50 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Vue | async data() on Wed, 27 Jan 2021 14:31:31 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/katz">@<bdi>katz</bdi></a> אמר ב<a href="/post/117810">Vue | async data()</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/men770">@<bdi>Men770</bdi></a></p>
<p dir="auto">תגדיר בdata משתנה עם ערך ריק<br />
ואחרי זה תכניס את הפונקציה לתוך mounted<br />
לדוגמא:</p>
<pre><code>mounted() {
fetch(config.apiEndpoint + 'book/' + this.$route.params.name).then(res =&gt; res.json())
}
</code></pre>
<p dir="auto">ואחרי זה אתה מוסיף שורה שמכניסה את ה Json לתוך המשתנה שהגדרת</p>
<p dir="auto">מקווה שהסברתי מספיק טוב!</p>
</blockquote>
<p dir="auto">אחרי זה ראיתי שכבר הסתדרת עם הרעיון הזה, סליחה על התגובה המאוחרת</p>
]]></description><link>https://tchumim.com/post/117811</link><guid isPermaLink="true">https://tchumim.com/post/117811</guid><dc:creator><![CDATA[katz]]></dc:creator><pubDate>Wed, 27 Jan 2021 14:31:31 GMT</pubDate></item><item><title><![CDATA[Reply to Vue | async data() on Wed, 27 Jan 2021 10:44:10 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/men770">@<bdi>Men770</bdi></a></p>
<p dir="auto">תגדיר בdata משתנה עם ערך ריק<br />
ואחרי זה תכניס את הפונקציה לתוך mounted<br />
לדוגמא:</p>
<pre><code>mounted() {
fetch(config.apiEndpoint + 'book/' + this.$route.params.name).then(res =&gt; res.json())
}
</code></pre>
<p dir="auto">ואחרי זה אתה מוסיף שורה שמכניסה את ה Json לתוך המשתנה שהגדרת</p>
<p dir="auto">מקווה שהסברתי מספיק טוב!</p>
]]></description><link>https://tchumim.com/post/117810</link><guid isPermaLink="true">https://tchumim.com/post/117810</guid><dc:creator><![CDATA[katz]]></dc:creator><pubDate>Wed, 27 Jan 2021 10:44:10 GMT</pubDate></item><item><title><![CDATA[Reply to Vue | async data() on Wed, 27 Jan 2021 08:11:59 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/men770">@<bdi>men770</bdi></a> אז הבעיה היא חתימת הפונקציה, כלומר קוד שבכלל לא הבאת פה, גם אם יש לזה פתרון אני לא יודע לומר אותו.</p>
]]></description><link>https://tchumim.com/post/117807</link><guid isPermaLink="true">https://tchumim.com/post/117807</guid><dc:creator><![CDATA[dovid]]></dc:creator><pubDate>Wed, 27 Jan 2021 08:11:59 GMT</pubDate></item><item><title><![CDATA[Reply to Vue | async data() on Wed, 27 Jan 2021 07:54:28 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/dovid">@<bdi>dovid</bdi></a> אמר ב<a href="/post/117805">Vue | async data()</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/men770">@<bdi>men770</bdi></a> לא מסכים עם השאלה, עם await צריך לעבוד מעולה ככה:</p>
<pre><code>const data = await fetch(config.apiEndpoint + 'book/' + this.$route.params.name).then(res =&gt; res.json())
return {
  book: data.book
}
</code></pre>
</blockquote>
<p dir="auto">כתבתי שזה לא עובד, כי בדקתי וזה לא עבד..<br />
כשאני עושה את הפונקציה של data בתור async, ‏vue מחזיר שגיאה, כי הפונקציה data צריכה להחזיר object, והיא מחזירה Promise.</p>
]]></description><link>https://tchumim.com/post/117806</link><guid isPermaLink="true">https://tchumim.com/post/117806</guid><dc:creator><![CDATA[Men770]]></dc:creator><pubDate>Wed, 27 Jan 2021 07:54:28 GMT</pubDate></item><item><title><![CDATA[Reply to Vue | async data() on Wed, 27 Jan 2021 07:47:10 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/men770">@<bdi>men770</bdi></a> לא מסכים עם השאלה, עם await צריך לעבוד מעולה ככה:</p>
<pre><code>const data = await fetch(config.apiEndpoint + 'book/' + this.$route.params.name).then(res =&gt; res.json())
return {
  book: data.book
}
</code></pre>
<p dir="auto">או:</p>
<pre><code>var root =  {
  book: data.book
}

fetch(config.apiEndpoint + 'book/' + this.$route.params.name)
        .then(res =&gt; res.json())
        .then(x =&gt; root.book = x.book);

return root;
</code></pre>
]]></description><link>https://tchumim.com/post/117805</link><guid isPermaLink="true">https://tchumim.com/post/117805</guid><dc:creator><![CDATA[dovid]]></dc:creator><pubDate>Wed, 27 Jan 2021 07:47:10 GMT</pubDate></item><item><title><![CDATA[Reply to Vue | async data() on Wed, 27 Jan 2021 07:19:34 GMT]]></title><description><![CDATA[<p dir="auto">ב"ה הסתדרתי לפי הדוגמא <a href="https://vuejs.org/v2/cookbook/using-axios-to-consume-apis.html#Base-Example" target="_blank" rel="noopener noreferrer nofollow ugc">כאן</a>.</p>
]]></description><link>https://tchumim.com/post/117804</link><guid isPermaLink="true">https://tchumim.com/post/117804</guid><dc:creator><![CDATA[Men770]]></dc:creator><pubDate>Wed, 27 Jan 2021 07:19:34 GMT</pubDate></item></channel></rss>