<?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.js | הגדרת משתנה גלובלי]]></title><description><![CDATA[<p dir="rtl">איך אני מגדיר ערך גלובלי שאני אוכל לגשת אליו מכל קובץ vue בפרוייקט הזה באמצעות <code>this.$value</code>?</p>
]]></description><link>https://tchumim.com/topic/13759/vue-js-הגדרת-משתנה-גלובלי</link><generator>RSS for Node</generator><lastBuildDate>Sat, 07 Nov 2026 22:59:02 GMT</lastBuildDate><atom:link href="https://tchumim.com/topic/13759.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 29 Jul 2022 14:31:30 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Vue.js | הגדרת משתנה גלובלי on Sun, 31 Jul 2022 20:21:52 GMT]]></title><description><![CDATA[<p dir="rtl">@ב-ל אמר ב<a href="/post/143527">Vue.js | הגדרת משתנה גלובלי</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/liy770" aria-label="Profile: liy770">@<bdi>liy770</bdi></a> אמר ב<a href="/post/143526">Vue.js | הגדרת משתנה גלובלי</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/yossiz" aria-label="Profile: yossiz">@<bdi>yossiz</bdi></a> תודה אבל משום מה אני מקבל ערך ריק...</p>
</blockquote>
<p dir="rtl">אם אתה בvue 3 זה לא יעבוד לך</p>
<p dir="rtl">וראה מה שכתבתי לעיל</p>
</blockquote>
<p dir="auto">vue2</p>
]]></description><link>https://tchumim.com/post/143528</link><guid isPermaLink="true">https://tchumim.com/post/143528</guid><dc:creator><![CDATA[liy770]]></dc:creator><pubDate>Sun, 31 Jul 2022 20:21:52 GMT</pubDate></item><item><title><![CDATA[Reply to Vue.js | הגדרת משתנה גלובלי on Sun, 31 Jul 2022 20:22:04 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/liy770" aria-label="Profile: liy770">@<bdi>liy770</bdi></a> אמר ב<a href="/post/143526">Vue.js | הגדרת משתנה גלובלי</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/yossiz" aria-label="Profile: yossiz">@<bdi>yossiz</bdi></a> תודה אבל משום מה אני מקבל ערך ריק...</p>
</blockquote>
<p dir="rtl">אם אתה בvue 3 זה לא יעבוד לך<br />
תכתוב כך</p>
<pre><code>app.config.globalProperties.msg = {xyz:xyz}
</code></pre>
<p dir="rtl">ועיין מה שכתבתי לעיל</p>
]]></description><link>https://tchumim.com/post/143527</link><guid isPermaLink="true">https://tchumim.com/post/143527</guid><dc:creator><![CDATA[ב.ל]]></dc:creator><pubDate>Sun, 31 Jul 2022 20:22:04 GMT</pubDate></item><item><title><![CDATA[Reply to Vue.js | הגדרת משתנה גלובלי on Sun, 31 Jul 2022 20:09:55 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/yossiz" aria-label="Profile: yossiz">@<bdi>yossiz</bdi></a> תודה אבל משום מה אני מקבל ערך ריק...</p>
]]></description><link>https://tchumim.com/post/143526</link><guid isPermaLink="true">https://tchumim.com/post/143526</guid><dc:creator><![CDATA[liy770]]></dc:creator><pubDate>Sun, 31 Jul 2022 20:09:55 GMT</pubDate></item><item><title><![CDATA[Reply to Vue.js | הגדרת משתנה גלובלי on Sun, 31 Jul 2022 11:21:01 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/liy770" aria-label="Profile: liy770">@<bdi>liy770</bdi></a> התכוונתי שתעשה ככה:<br />
בקובץ הראשי:</p>
<pre><code>Vue.prototype.$values = { xyz: "xyz" };
</code></pre>
<p dir="rtl">בגישה לערך מקובץ אחר:</p>
<pre><code>this.$values.xyz
</code></pre>
<p dir="rtl">כתיבה לערך:</p>
<pre><code>this.$values.xyz = "abc"
</code></pre>
<p dir="rtl">זה היה לפי מה שהחלטת שאתה רוצה לגשת אליו ככה,<br />
הייתי ממליץ במקום זה לשים את הערך בקובץ נפרד, משהו כזה:</p>
<p dir="auto">xyz.js</p>
<pre><code>let xyz = "xyz"

export function setXyz(val) {  xyz = val }

export function getXyz() { return xyz }
</code></pre>
<p dir="rtl">והשימוש:</p>
<pre><code>import { getXyz, setXyz } from './xyz'

let xyz = getXyz
setXyz(xyz + "123")
</code></pre>
<p dir="rtl">אם אתה רוצה שהערך יהיה ריאקטיבי (כלומר שהאפליקציה תגיב לשינויים בערך) צריך להשתמש בשירותים של vue לעשות אותו ריאקטיבי, אני לא כל כך מכיר</p>
]]></description><link>https://tchumim.com/post/143499</link><guid isPermaLink="true">https://tchumim.com/post/143499</guid><dc:creator><![CDATA[yossiz]]></dc:creator><pubDate>Sun, 31 Jul 2022 11:21:01 GMT</pubDate></item><item><title><![CDATA[Reply to Vue.js | הגדרת משתנה גלובלי on Sat, 30 Jul 2022 21:09:39 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/liy770" aria-label="Profile: liy770">@<bdi>liy770</bdi></a> אמר ב<a href="/post/143468">Vue.js | הגדרת משתנה גלובלי</a>:</p>
<blockquote>
<p dir="rtl">(אני צריך משתנה שאני יוכל לגשת אליו מכל קובץ בפרוייקט)</p>
</blockquote>
<p dir="rtl">בשביל יש את <a href="https://vuex.vuejs.org/guide/" target="_blank" rel="noopener noreferrer nofollow ugc">store</a></p>
]]></description><link>https://tchumim.com/post/143473</link><guid isPermaLink="true">https://tchumim.com/post/143473</guid><dc:creator><![CDATA[חוקר]]></dc:creator><pubDate>Sat, 30 Jul 2022 21:09:39 GMT</pubDate></item><item><title><![CDATA[Reply to Vue.js | הגדרת משתנה גלובלי on Sat, 30 Jul 2022 20:35:39 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/yossiz" aria-label="Profile: yossiz">@<bdi>yossiz</bdi></a> אמר ב<a href="/post/143465">Vue.js | הגדרת משתנה גלובלי</a>:</p>
<blockquote>
<p dir="rtl">ב) להגדיר ש-$value הוא מסוג אובייקט ותמיד תיגש לשדה בתוכו, כך תקבל תמיד גם בכתיבה וגם בקריאה את אותה שדה.</p>
</blockquote>
<p dir="rtl">סורי אבל פחות הבנתי...<br />
(אני צריך משתנה שאני יוכל לגשת אליו מכל קובץ בפרוייקט)</p>
]]></description><link>https://tchumim.com/post/143468</link><guid isPermaLink="true">https://tchumim.com/post/143468</guid><dc:creator><![CDATA[liy770]]></dc:creator><pubDate>Sat, 30 Jul 2022 20:35:39 GMT</pubDate></item><item><title><![CDATA[Reply to Vue.js | הגדרת משתנה גלובלי on Sat, 30 Jul 2022 20:13:53 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/liy770" aria-label="Profile: liy770">@<bdi>liy770</bdi></a> זה כבר לא קשור ל-VUE אלא ל-JS.</p>
<p dir="rtl">יש הבדל ב-JS בין קריאה של שדה לכתיבה לתוך שדה.<br />
בקריאה, אם השדה לא קיימת אז JS בודק את שרשרת הפרוטוטייפים, ומחזיר את הערך משם אם זה קיים שם.</p>
<p dir="rtl">לעומת זאת, בכתיבה לשדה, זה תמיד יהיה על האובייקט עצמו ולא על הפרוטוטייפ.</p>
<p dir="rtl">(נראה לי שההסבר פשוט, כי JS לא מבחין בין פעולת יצירת השדה לבין פעולת הכתיבה לשדה, שניהם נעשים על ידי השמה לתוך השדה, ואם השדה לא קיימת זה מיוצר אוטומטית, לכן אין דרך לדעת שהתכוונת לפרוטוטייפ ולא לאובייקט עצמו)</p>
<p dir="rtl">יש שתי פתרונות לצורך שלך:</p>
<blockquote>
<p dir="auto"><img src="https://tchumim.com/assets/plugins/nodebb-plugin-emoji/emoji/android/2139.png?v=cf1b4e11576" class="not-responsive emoji emoji-android emoji--information_source" style="height:23px;width:auto;vertical-align:middle" title=":information_source:" alt="ℹ" /> אני מתייחס ל"צורך" בצורה צרה מאוד, כלומר רק לצורך המוצהר של <em>"ערך גלובלי שאני אוכל לגשת אליו מכל קובץ vue בפרוייקט הזה באמצעות <code>this.$value</code>"</em>. יש דרכים יותר טובות לניהול state גלובלי</p>
</blockquote>
<p dir="rtl">א) תוכל לכתוב לשדה על ידי <code>this.constructor.prototype.$value</code><br />
ב) להגדיר ש-<code>$value</code> הוא מסוג אובייקט ותמיד תיגש לשדה בתוכו, כך תקבל תמיד גם בכתיבה וגם בקריאה את אותה שדה.</p>
<pre><code>Vue.prototype.$values = { value };
</code></pre>
]]></description><link>https://tchumim.com/post/143465</link><guid isPermaLink="true">https://tchumim.com/post/143465</guid><dc:creator><![CDATA[yossiz]]></dc:creator><pubDate>Sat, 30 Jul 2022 20:13:53 GMT</pubDate></item><item><title><![CDATA[Reply to Vue.js | הגדרת משתנה גלובלי on Sat, 30 Jul 2022 19:54:23 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/shaya" aria-label="Profile: Shaya">@<bdi>Shaya</bdi></a> אמר ב<a href="/post/143450">Vue.js | הגדרת משתנה גלובלי</a>:</p>
<blockquote>
<p dir="rtl">בתוך <code>main.js</code>:</p>
<pre><code>Vue.prototype.$value = value;
</code></pre>
</blockquote>
<p dir="rtl">זה רק בvue2</p>
]]></description><link>https://tchumim.com/post/143464</link><guid isPermaLink="true">https://tchumim.com/post/143464</guid><dc:creator><![CDATA[ב.ל]]></dc:creator><pubDate>Sat, 30 Jul 2022 19:54:23 GMT</pubDate></item><item><title><![CDATA[Reply to Vue.js | הגדרת משתנה גלובלי on Sun, 31 Jul 2022 11:26:29 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/liy770" aria-label="Profile: liy770">@<bdi>liy770</bdi></a><br />
<a href="https://vuejs.org/api/application.html#app-config-globalproperties" target="_blank" rel="noopener noreferrer nofollow ugc">https://vuejs.org/api/application.html#app-config-globalproperties</a></p>
<pre><code>app.config.globalProperties.msg = 'hello'
</code></pre>
<p dir="rtl">זה מיועד לשמירת ערך קבוע שיהיה זמין בכל הדפים.<br />
אם אתה רוצה ערך שיהיה ניתן להגדרה ושינוי בכל מקום תשתמש בקובץ חיצוני עם ref עיין <a href="https://vuejs.org/guide/scaling-up/state-management.html" target="_blank" rel="noopener noreferrer nofollow ugc">כאן</a> או עם vuex / <a href="https://pinia.vuejs.org/" target="_blank" rel="noopener noreferrer nofollow ugc">pinia</a></p>
]]></description><link>https://tchumim.com/post/143463</link><guid isPermaLink="true">https://tchumim.com/post/143463</guid><dc:creator><![CDATA[ב.ל]]></dc:creator><pubDate>Sun, 31 Jul 2022 11:26:29 GMT</pubDate></item><item><title><![CDATA[Reply to Vue.js | הגדרת משתנה גלובלי on Sat, 30 Jul 2022 19:26:21 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/shaya" aria-label="Profile: Shaya">@<bdi>Shaya</bdi></a> אמר ב<a href="/post/143450">Vue.js | הגדרת משתנה גלובלי</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/liy770" aria-label="Profile: liy770">@<bdi>liy770</bdi></a><br />
בתוך <code>main.js</code>:</p>
<pre><code>Vue.prototype.$value = value;
</code></pre>
</blockquote>
<p dir="rtl">אני יכול לערוך אותו ע״י <code>this.$value = "a"</code>?<br />
ניסיתי וזה לא עבד...</p>
]]></description><link>https://tchumim.com/post/143456</link><guid isPermaLink="true">https://tchumim.com/post/143456</guid><dc:creator><![CDATA[liy770]]></dc:creator><pubDate>Sat, 30 Jul 2022 19:26:21 GMT</pubDate></item><item><title><![CDATA[Reply to Vue.js | הגדרת משתנה גלובלי on Fri, 29 Jul 2022 15:35:37 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/liy770" aria-label="Profile: liy770">@<bdi>liy770</bdi></a><br />
בתוך <code>main.js</code>:</p>
<pre><code>Vue.prototype.$value = value;
</code></pre>
]]></description><link>https://tchumim.com/post/143450</link><guid isPermaLink="true">https://tchumim.com/post/143450</guid><dc:creator><![CDATA[Shaya]]></dc:creator><pubDate>Fri, 29 Jul 2022 15:35:37 GMT</pubDate></item></channel></rss>